Введите текст в терминал iTerm из сценария Apple

770
Artsiom Miklushou

Я пытаюсь вставить текст из сценария Apple в 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

1 ответ на вопрос

3
user3439894

write text Команда выполняется в пределах current session, так что используйте следующий пример AppleScript код :

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 команду, чтобы позволить iTerm полностью активироваться перед выполнением командwrite text или .keystroke

Похожие вопросы