I want to be able to open the terminal application and have it either automatically run a script that opens several tabs and run an arbitrary set of commands in each. For example I would like one tab to open, change directories, and run a rails server; have another open, change directories, and tail a log file; etc..
Is there a way to do this either with a shell script or applescript?
I found this question but it seems to hang if I want to open tabs with commands that don't end (like running the rails server).
Best Answer
This is a little bit hacky, but you can achieve this in AppleScript. If there is a predetermined number of tabs you want, and preset commands you wish to run, this isn't difficult.
Of course, replace
firstCommand
with whichever command you actually want to run, and so on. For whatever reason, Terminal doesn't really have an accessible way to create new tabs through AppleScript, so the long, hacky looking line in the middle just tells Terminal to type ⌘T to open that new tab, and then new commands will execute in it.You can run this AppleScript as is, or use it in Automator to create a new service, which you can then execute from anywhere using a keyboard shortcut if you'd like.
Extras - If you want to fire some script/command in the newly opened terminal session, you can refer this