Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way with Applescript to launch multiple tabs in Terminal and execute commands against them?

I have a project that requires me to launch several services in Terminal to run and monitor simultaneously and would like to automate that start-up process.

share|improve this question
up vote 1 down vote accepted

One option is to use System Events to send the keystroke necessary to create the new tab, but the limitation is that Assistive Devices in Universal Access must be turned on and adding a sight delay may be necessary.

tell application "System Events" to tell process "Terminal" to keystroke "t" using command down

As far as I can discern from the Terminal script dictionary - you can only retrieve information from tabs but not create new ones as you could with windows (eg. Run do script "clear"

share|improve this answer

Looks like you can use GUI scripting. (I'd have expected to be able to make new tabs without resorting to GUI scripting, since Terminal's dictionary knows tabs as elements of windows. Apparently broken, though.) As with Chealion's answer, access for assistive devices must be turned on but Apple provides a script that allows you to check that it's on here.

Matthew Lambie provides an example of using AppleScript's GUI scripting to create tabs in here:

This answer would have been better as a comment to Chealion's answer but I don't have the rep to make comments yet.

share|improve this answer

I'm not sure how to get the tabs but this will get you multiple windows:

set commands to {"ls", "pwd", "cd /tmp; ls"}

repeat with com in commands
    tell application "Terminal"
    	do script with command com
    end tell
end repeat


share|improve this answer

iTerm has good scripting support. AFP 548 has an example that opens multiple ssh sessions in different tabs. [I suspect this will be easier to do and more reliable than GUI scripting.]

share|improve this answer

I know you asked for Terminal, but really - you should be using iTerm :-)

This is from a script written by a coworker for iTerm:

  osascript <<-eof
	tell application "iTerm"
		set myterm to (make new terminal)
		tell myterm
			launch session "Default session"
			tell the last session
				set name to "Server"
				write text "cd \"$PROJECT_DIR\""
				write text "script/server"
			end tell

			launch session "Default session"
			tell the last session
				set name to "Console"
				write text "cd \"$PROJECT_DIR\""
				write text "script/console"
			end tell

		end tell
	end tell

It launches a new iTerm-window with multiple tabs, and does some small commands in them (for Rails development).

share|improve this answer

I created a scriptable way to allow one to create and title new tabs from the same window using a new_tab(title, command) shell function that basically wraps around all the apple scripting.

My article with the code and some backstory can be found here: Programmatically Create & Title Tabs Within The Mac OS X

I hope this makes someone's life a bit more automated :)

share|improve this answer

Your Answer


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.