In OS X, how do I set up an AppleScript to
- open a new iTerm2 tab
- change to a directory
- clear the console
- echo the current directory
I had something like this before for regular Terminal, but I can't even find the scripting guide for iTerm2.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
Daniel's solution somehow opens a new Window – also, the
exec command statement does not work as expected. One has to
write text instead.
Also, you have to use
launch session "Default Session"
in order to get a new tab.
The following does what you asked for:
tell application "iTerm" make new terminal tell the current terminal activate current session launch session "Default Session" tell the last session write text "cd ~/Downloads; clear; pwd" end tell end tell end tell
Not on a Mac right now, so it might not work 100% (adapted this answer of mine).
tell application "iTerm" activate set t to (make new terminal) tell t tell (make new session at the end of sessions) exec command "cd Downloads" exec command "clear" exec command "pwd" end tell end tell end tell
You can probably concatenate the commands to
cd Downloads ; clear ; pwd