2

I'm trying to paste text from apple script to 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

But i'm getting an error:

iTerm got an error: Can’t get keystroke "command" of current tab of current window.

Any ideas how to fix this?

As I here there is available write text command https://www.iterm2.com/documentation-scripting.html

1 Answer 1

7

The write text command is done within the current session, so use the following example AppleScript code:

activate application "iTerm"
tell application "iTerm"
    tell current session of current window
        set cmd to "command"
        write text cmd
    end tell
end tell

To use the keystroke command use 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

Note: You may need to strategically place a delay command to allow iTerm to fully activate before the write text or keystroke commands are executed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .