Last Updated: February 25, 2016
·
2.147K
· vpetro

Use Alfred to launch an iTerm2 tab with a named profile

iTerm2 does allow to set a keyboard shortcut to create a tab with a specific profile. However, I never remember the key combination for this. Instead, I decided to add an extension in Alfred that will do the same thing.

The code for the extension is as follows:

on alfred_script(q)
    tell application "iTerm"
        activate
        set myterm to (current terminal)
        tell myterm
            set mysession to (launch session "server")
            tell mysession
                set name to q
                set myVar to "ssh " & q
                write text myVar
            end tell
        end tell
    end tell
end alfred_script

I have the extension triggered on keyword rt. This allows Alfred commands such as rt server_name. Where the server_name is an alias in my SSH config. This will create a new tab using the server profile and ssh to the server.

The following links were extremely helpful during the creation of the extension.

[1] http://www.goulbourn.com/2012/12/alfreditermssh.html
[2] http://hints.macworld.com/article.php?story=20070409141256538