Terminal.app window tab groups

2012 04 13

Here’s a fun one: if you ever find yourself setting up a Terminal.app window with the same set of tabs, running the same set of (let’s say) daemons over and over again, you can try out this little helper script.


while (( "$#" )) ; do
	let I=$TOTAL-$#
	if [ $I -eq 0 ] ; then
		# first command: need a new window
		osascript -e "tell application \"Terminal\" to \
		  do script" >/dev/null
		# subsequent commands: new tab in that window
		osascript -e "tell application \"System Events\" to \
		  tell process \"Terminal\" to \
		    keystroke \"t\" using command down" >/dev/null
	osascript -e "tell application \"Terminal\" to \
	  do script \"$1\" in selected tab of the front window" >/dev/null

Use it by writing one script per window-tab-group you want to be able to easily spawn.


terminal-tab-group.bash \
    "first-daemon" \
    "cd /some/path && ./second-daemon -f -l -a -g -s" \
    "/usr/sbin/third-daemon" \