Split window programmatically with iTerm

bashiterm2scriptterminalzsh

on my development workstation I often have to start the same commands every morning.

zeus start, zeus server (booting rails via zeus), redis-server, and like 3 others.

I know a lot of people would say have them running all the time but I do a lot of work on my own stuff and it wigs me out having all of those running while I'm working on separate rails projects.

Is there some kind of advanced alias I can make which starts all of these from one command, ideally by programmatically splitting the window (like ⌘-D).

I'm using iTerm2 with oh-my-zsh.

I wouldnt mind if they were all in the same window I suppose (somehow running as background processes) however I do need to sometimes look at the output, and work with the output from each command, so I'm not sure how that would work.

Thanks!

Best Answer

You can easily call this from iTerm2 directly to simulate pressing D:

osascript -e 'tell application "System Events" to key code 2 using command down'

For this to work you want to start the programs in background, since otherwise you cannot run osascript:

some-command &
osascript -e '…'

From there on you'll land in a new iTerm2 window, so you need to use the write text option in AppleScript to run further shell commands. See here for more: How do I set up an AppleScript to open a new iTerm2 tab and change the directory?

Related Question