Take the 2-minute tour ×

I've recently converted to using zsh instead of bash in OSX and was wondering if it is possible to do the following:

When I launch my terminal I would like to start various tabs and have each tab run a different process e.g tailing logs, running ruby scripts etc.

Currently I need to cmd+n multiple tabs and then manually start each process. While this doesn't take long I would like to be able to just launch my terminal and have these various tabs start and run those commands automatically.

Is this possible?

share|improve this question

migrated from serverfault.com Dec 14 '12 at 18:59

This question came from our site for system and network administrators.

This sort of thing really shouldn't be handled by your shell. Look into screen multiplexers, like GNU Screen or tmux. These can easily be configured to do what you are asking about, and as an added benefit, you can start a long-running process, then detach from that window, then re-attach later if needed. –  EEAA Dec 11 '12 at 3:47
You could also create specific Terminal window configurations that start the desired program when opened instead of a login shell. –  Daniel Beck Dec 28 '12 at 13:28

1 Answer 1

I had a similar question some time ago. Far as I can tell, the only way to script Terminal actions is using applescript (after all, Terminal.app is a GUI app and AppleScript is Apple's intended way of scripting GUI actions).

Write a script like the following:

tell application "Terminal"
    do script "cd /path_to/target_dir" in front window
    do script "some_command" in front window
end tell

tell application "System Events" to tell process "Terminal" to keystroke "t" using command down

tell application "Terminal"
    do script "cd /path_to/next_target_dir" in front window
    do script "some_other_command" in front window
end tell


Repeat as many times as needed for the requisite number of commands. Note that's for tabs, which you specifically requested, although the mentioned "cmd-N" keystroke opens new windows, not tabs. Change "t" to "n" in the 'tell application "System Events"...' line if you want to do this with windows.

share|improve this answer
Yep - this would work. Thanks. –  calumbrodie Jan 9 '13 at 20:27

Your Answer


