Jump to content
rheckart

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?

Share this post


Link to post

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


Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...