I need to open some terminal sessions via iTerm 2 and execute commands on each terminal (e.g. rails s ; rails c)

How to do it via automator or alfred?

1 Answer 1


You could do it with an Alfred Worflow (you need the Powerpack).

First create a Blank Workflow and fill the data:

enter image description here

Use the plus symbol in the right cornet to add Trigger → Hotkey action. Define your prefered hotkey and save it.

enter image description here

Add Actions → Run script. Use /usr/bin/osascript as language. Paste the following script and save it. Change ls -l to whatever command you want to execute.

tell application "iTerm"
    set the clipboard to "ls -l"
    delay 0.5
    tell application "System Events"
        keystroke "v" using command down
        keystroke return
    end tell
end tell

enter image description here

Connect the two actions and you will be ready.

enter image description here

enter image description here

Type your hotkey and it will open iTerm and execute your command.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .