So I fired up Script Editor and figured I'd hack together something to fire up the terminal, run a command, open a new tab, run another command and so on. Not exactly elegant, but a good place to start. Finally a great use for AppleScript. Then, I started to peruse the dictionary for Terminal.app. Dead end. Maybe AppleScript wasn't the right choice (or a choice at all) here. Maybe I'll give Automator another shot. WOW, even more of a dead end. So, off to Google I went.
Strangely I don't seem to be the first to ponder the steps we go through just to start working. After searching a bit I came across this article by Solomon White. Sounded a bit familiar, so at least my initial thoughts were completely insane - I mean why can't I tell my Apple to do the things I know it can do using Apple's own scripting language? So I read further. Solomon mentioned RubyOSA, which I think I had a brief interlude with one late night months back. Seems that doesn't do the trick either, RubyOSA seems to work best with applications that are more AppleScript-able. Luckily it seems that Matt Mower found a better way to handle all this and wrote about it in his "Scripting a better 'cd' and then some" article. Which is where I learned of ruby appscript which, according to the appscript website, is a user-friendly Apple even bridge. Although the statement "Appscript makes these languages serious alternatives to Apple's own AppleScript language for automating your Mac." in the description of appscript did give me a bit of a pause - since of course AppleScript had just left me confused and with a serious headache. So a quick "sudo gem install rb-appscript" and I was ready to start hacking. By this point the feature set had already expanded greatly in my head - because seriously if I can open new tabs in Terminal and run commands, why couldn't I fire up a browser and point it to localhost:3000?
So I then sat down to work out a script that would do the following:
In Terminal:
- Boot Mongrel
- Start script/console
- Start autotest
- Start IRB
- Open the project directory in TextMate using "mate ."
Then once things were up and running it would:
- Launch Safari if it wasn't already running
- Launch Firefox if it wasn't already running
- Point all the browsers to the site
- Bring TextMate to the forefront
- While we are at it go ahead and close the tab that ran the "mate ." - we don't need any extra tabs...
Luckily a lot of folks have done a lot of work ahead of me and I was able to cobble together something that accomplished my goals - so thanks to Soloman, Matt, Hamish Sanderson (rb-appscript) and a lot of other random AppleScript snippets I found searching mailing lists along the way. Without the work they'd done I'd still be starting to work on my projects the traditional way!
Well it's getting late here, I've got a terrible head-cold and I think it's time to hit the hay.
Coming up:
Part two - the initial Terminal steps with a sweet YAML config file so this has value on multiple projects.
Part three - using appscript to launch browsers and point them in the right direction.
Part four - tying it all together - the final script, installing the script and actually getting to work on a project!
Blogged with Flock
No comments:
Post a Comment