Open iTerm bookmarks from the iTerm command line

Apr 11, '07 07:30:00AM

Contributed by: joeyGibson

I wanted to be able to launch iTerm bookmarks from within an iTerm shell. Using two files, a shell script and an AppleScript, I can now do this. The first file, called it, is a simple shell script that calls the AppleScript. Here it is:

#!/bin/bash

if [[ $# == 0 ]]
then  
  echo "Usage: it "
  exit
fi

osascript ~/bin/it.scpt $*
Here's the AppleScript itself, called it.scpt:
on run argv
  tell application "iTerm"
    activate
    tell the first terminal
      launch session (item 1 of argv)
    end tell
  end tell
end run
The shell script makes certain you specified a bookmark to open. Then it calls it.scpt, passing in the session name you asked for. it.scpt will tell iTerm to open the appropriate bookmark in a new tab, which is exactly what I wanted. You can see the code snippets in all their syntax-highlighted glory here if you want, with a bit more info. Note that I have both files living in my ~/bin directory, but you can put them wherever you want, changing the shell script as needed.

Comments (9)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20070409141256538