Update : iTerm2 v3 has significantly improved, but incompatible support for AppleScript - see https://www.iterm2.com/documentation-scripting.html
To provide some background @Joel's own answer:
iTerm 2 AppleScript Support (with iTerm 2 v1.0.0.201306220):
incomplete : script support for split panels is missing, so the OP resorts to a suboptimal method for sending keystrokes.
demonstrates some strange behavior : when compiling (in the AppleScript editor) the tell "System Events" ... instruction tell "System Events" ... inside the tell application "iTerm" prefix i term application inexplicably inserted before the "System Events" - since the code below is not precompiled, this prefix is ββnot included to avoid future problems.
it has bugs / are incompatible with its dictionary : what the dictionary describes as an exec command, which actually does not work, is actually executed by the write text command: it executes the passed argument or - if the argument has a finite space - it simply βtypesβ the argument, does not sending it.
Here's a solution with broken panels based on a workaround (sending keystrokes) - a bash script calls AppleScript code through osascript :
Limitations due to the fact that panels are not part of the dictionary:
- another open panel cannot be named
- no command can be sent to another panel
#!/usr/bin/env bash projectFolder="$HOME/Desktop" # example osascript <<-EOF tell application "iTerm" tell (make new terminal) # Create a new pseudo terminal... tell (launch session "Default session") # ... and open a session (window) # Name the new window (its original pane). set name to "Server" # Execute the 'cd' command in the original pane. write text "cd '$projectFolder'" # Create a new split pane, horizontally, by sending ββ§-D tell application "System Events" to keystroke "d" using {shift down, command down} # !! Note: We canNOT: # - name this pane separately # - execute a command in it. # Return to the original pane, by sending β-[ tell application "System Events" to keystroke "[" using {command down} end tell end tell end tell EOF
source share