Jan
29
iTerm2: advanced features
January 29, 2011 | 5 Comments
At bluekiwi, I constantly have no less than 10 opened terminal sessions at the same time. Because it is so easy to launch a command in the wrong window (on the wrong server), I got used to always order my tabs the same way and always give them the same name. As I needed more and more shell windows to work, this little routine started to take me more time than I care to spend on every Monday morning. Laziness is also the Mother of Invention so I set out to script my iTerm in order to reset my workspace after a computer reboot.
Googling iTerm lead me to a few more improvements…
iTerm2
First, iTerm2 is a fork of iTerm hosted on Google Code which has been a lot more active lately than the original iTerm. I downloaded it and replaced the iTerm1 with this new one.
Good news, while all my profiles and bookmarks were conserved, the profile and bookmarks management was greatly simplified. I recommend you to upgrade, too.
Growl
iTerm and iTerm2 both support Growl notifications. That means you can display a message in Growl from your scripts with the follwing command :
1 | echo $'\e]9;hello\007' |
Since this is a hard command to remember, Damon Parker suggested adding the following line to your .bashrc or your .bash_profile
1 | growl() { echo -e $'\e]9;'${1}'\007' ; return ; } |
So, if your starting a command that will run for a while and want to be notified when it’s completed, you can do
1 | long_cmd ; growl "command completed" |
Visor
One of the features introduced by the iTerm2 team is the “Visor”. Visor is an existing tool for Terminal allowing you, with a simple hotkey, to make the terminal appear on top of any running app.
To use this feature with iTerm2, no need to install anything extra. Simply edit your preference and choose a Visor hotkey.

A nice little addition to the iTerm I was used to.
Dashboard widget
There is a Dashboard Widget for iTerm allowing you to run quick commands from the Mac OS X Dashboard.
Last but not least, the launch script
AppleScript was already compatible with iTerm and this feature was conserved in iTerm2 so that I can automate the creation of my iTerm workspace.
Below is an example of the type of things I do when launching my iTerm workspace like opening a tab in a given folder and running svn up. Emptying a log file and tailing it. Launching memcache in a dedicated tab. Opening a bookmarked session on a remote server, etc.
Below is an example of a working AppleScript.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | -- iTerm launching script for samo9789 launch "iTerm" tell application "iTerm" activate -- talk to the new terminal tell the first terminal -- set terminal size set number of columns to 200 set number of rows to 60 -- launch a default shell in a new tab in the same terminal --launch session "Default" -- this is automatically done at iTerm launch -- create the project tab launch session "Default" tell the last session set name to "project" write text "cd Workspace/my_project" write text "svn up" end tell -- create the project log tab launch session "Default" tell the last session set name to "project logs" write text "echo 'Logs for Project' > project.log" write text "tail -f project.log" end tell -- create the memcached tab launch session "Default" tell the last session set name to "memcached" write text "memcached -vv" end tell --open a named bookmark launch session "my_bookmark" end tell end tell |
Finally, to use the script, you must :
- either save it as an application in the Apple Script Editor (File > Save as) which you’ll be able to run from Spotlight, Albert, Quicksilver or any launcher you are using
- save the scripts as ~/Library/Application Support/iTerm/AutoLaunch.scpt in which case the script will run when you launch iTerm - everytime
Split Panes
Another good news is that iTerm2 introduced split panes. I’ve just tweeted the developer hoping to learn how to script the creation of split panes. Stay tuned…
Update :
Another iTerm2 user suggested the following Apple Script to create split plane (until the developer gets back to us with official support). You can see his contribution on Google Code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <<EOF tell application "iTerm" activate set myterm to (make new terminal) tell myterm launch session "Panes" set number of columns to 244 set number of rows to 73 tell application "System Events" to keystroke "d" using command down tell application "System Events" to keystroke "d" using command down tell application "System Events" to keystroke "D" using command down tell application "System Events" to keystroke "D" using command down tell application "System Events" to key code 123 using {command down, option down} tell application "System Events" to keystroke "D" using command down tell application "System Events" to keystroke "D" using command down tell application "System Events" to key code 123 using {command down, option down} end tell end tell EOF |
Anyway, this is a welcomed feature!
And a few more tricks…
- a script creating a “term” command by Damon Parker. The command allows you to open a new session with arguments such as current directory or a command to run. Pretty handy!
- open iTerm with the current Finder window pwd as current directory with this Apple Script by Simon Dorfman
- several scripts and commands to interact betweem iTerm and the Finder as well as between TextMate and iTerm by xanana
Tagged with: apple script, apple script editor, bash, command, console, finder, growl, iterm, terminal, textmate
Liked this page?
Subscribe to the RSS feed or sign up for the newsletter now.


New blog post: iTerm2: advanced features: At bluekiwi, I constantly have no less than 10 opened terminal session… http://bit.ly/hNcpoC
@gnachman Thanks!. Feature request filed. Just blogged about my migration from iTerm to iTerm2: http://t.co/FaAHpGc Great job!
[...] iTerm2: advanced features [...]
Update:
I just updated this post sharing a solution (provided by another user on Google Code http://code.google.com/p/iterm2/issues/detail?id=559) to script the creation of split panes
Great tips here! Love the growl integration!