Scripting Terminal.app to setup my Sakai workspace

With my software development I require a few Terminal windows or tabs open at any one time. Normally at least 4. When Terminal.app came out with tabbed Terminal, I quickly realised that ‘Save Windows as Group’ doesn’t really do much.

I mean, great, I can setup my tabs and save them so it will automatically give me 4 tabs in a window. But I could just hit command-T a few times too. What I really wanted was the ability to save the state of each of those tabs, ie which directory I am in, which command is currently running etc.

So I came up with some AppleScript a while back for doing exactly what I want, and now on the odd occasion that I need to restart my Mac, I just run this Applescript to setup my Terminal workspace rather than doing it all manually each time.

(Open terminal and load up tabs with the specified commands, Steve Swinsburg, November 2008)

set cols to 160
set rows to 30
set commands to {"cd ~/dev/eclipse/profile2/", "cd ~/dev/sakai/src/cafe-2.5.x/profile2/", "cd ~/dev/sakai/init.d/", "cd ~/dev/sakai/tomcat/cafe-2.5.x/logs && tail -f catalina.out"}
repeat with command in commands
  new_tab(command)
end repeat

on new_tab(command)
  tell application "Terminal"
    activate
    tell application "System Events" to tell process "Terminal" to keystroke "t" using command down
    do script command in selected tab of the front window
  end tell
end new_tab

Just open Applications/AppleScript/Script Editor.app, paste that in, change the actual commands to what you want, add and delete command as necessary (depending on how many Terminal tabs you want), save and run! You can even save it as an Application with startup screen to confirm that you really want to run it etc.

I’ve got one for my current development, one for my Sakai branch management workspace, can be applied to anything. I *really* love that you can run the command inside the Terminal tab when it opens.

Note to Apple: Implement this feature in ‘Save Windows as Group’!

Advertisements

2 thoughts on “Scripting Terminal.app to setup my Sakai workspace

  1. Excellent!

    As I am a real newbie, I was wandering how you would change your code to:

    A) open new windows instead of tabs ?

    B) open a specified “window group” (so that the terminal windows are located as wanted) ?

    Thanks anyway.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s