Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 professional system and network administrators.

1  
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
add comment

1 Answer

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"
    activate
    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"
    activate
    do script "cd /path_to/next_target_dir" in front window
    do script "some_other_command" in front window
end tell

...etc

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.