5

Terminal.app window tab groups

 2 years ago
source link: https://peter.bourgon.org/blog/2012/04/13/terminal.app-window-tab-groups.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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.

#!/bin/bash

TOTAL=$#
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
	else
		# 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
	fi
	osascript -e "tell application \"Terminal\" to \
	  do script \"$1\" in selected tab of the front window" >/dev/null
	shift
done

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

#!/bin/sh

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

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK