我正在尝试将文本从苹果脚本粘贴到 iTerm 中。
activate application "iTerm"
tell application "iTerm"
tell current tab of current window
set cmd to "command"
keystroke cmd
keystroke return
end tell
end tell
但我收到了一个错误:
iTerm 出现错误:无法获取当前窗口当前选项卡的按键“命令”。
任何想法如何解决这一问题?
正如我在这里有可用的write text
命令https://www.iterm2.com/documentation-scripting.html
答案1
这write text
命令在内完成current session
,因此使用以下例子 苹果脚本 代码:
activate application "iTerm"
tell application "iTerm"
tell current session of current window
set cmd to "command"
write text cmd
end tell
end tell
要使用keystroke
命令使用System Events
:
activate application "iTerm"
tell application "iTerm"
tell current tab of current window
set cmd to "command"
tell application "System Events"
keystroke cmd
keystroke return
end tell
end tell
end tell
笔记:您可能需要策略性地放置delay
命令允许终端完全激活之前write text
或keystroke
命令被执行。