Jump to content

Using ttab in a Terminal Command with Workflows


Recommended Posts

I want to make a workflow that opens several tabs in a Terminal window, each doing something different. I discovered this ttab project that seems to do what I want, but it's not working correctly in my Workflow.

 

When I enter a Terminal command as simple as ttab postgres -D /usr/local/var/postgres, the Workflow keeps executing the command over and over in new tabs, creating a race condition.

 

How can I get this to run the command once and stop? Or is there a better way in a Workflow to to open new Terminal tabs and execute commands within them?

Link to comment

Not sure if this is exactly what you are after but it may help. It is an applescript I picked up somewhere.

tell application "Terminal"
	activate
	
	-- Get a window that's not busy.
	-- If there are no open windows, open one.
	if (count of windows) is greater than 0 then
		repeat with currentWindow in windows
			if currentWindow is not busy then
				set targetWindow to currentWindow
			end if
		end repeat
	else
		do script ""
		set targetWindow to window 1
	end if
	
	-- Do command 1.
	set firstCommand to "ls"
	do script firstCommand in targetWindow
	
	-- Open a new tab.
	tell application "System Events" to tell process "Terminal" to keystroke "t" using command down
	
	-- Do command 2.
	set secondCommand to "pwd"
	do script secondCommand in targetWindow
	
	-- And so on...
end tell


Link to comment
  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...