How do I run an iTerm session from the command line, passing in the command which is to be executed in the iTerm window?
The xterm analog is -e
, i.e.
xterm -e sleep 10
-c, –command: This option is used when we want to run a particular command rather than interactive shell and get terminal information in the file given as argument or typescript by default. The script will automatically exit after successful execution.
I had found the official documentation, but hadn't thought to wrap the Applescript up with osascript like SushiHangover- very nice. His answer didn't work for me, probably because I'm using the latest beta 3.0 version, so here's one that does work (and also simplifies a bit).
#!/bin/bash
osascript - "$@" <<EOF
on run argv
tell application "iTerm"
activate
set new_term to (create window with default profile)
tell new_term
tell the current session
repeat with arg in argv
write text arg
end repeat
end tell
end tell
end tell
end run
EOF
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With