4.10.2008

Wedding Site Launched

So I've finally completed enough of the wedding site to launch. I'm definitely rolling out a limited set of functions with plans to add features in the near future.

so check it out www.carrieandjonwedding.info.

4.05.2008

Test of Code Formatting

I'm checking to see how this shows up with some new CSS that matches my TextMate environment.





safari = OSA.app('Safari')

for u in URLS
this_url = "http://www."+u #format the URL
safari.activate
safari.documents[0].url=(this_url)
sleep(2)
snapz.capture
end




This is from the monokai theme for TextMate by Wimer Hazenberg (http://www.monokai.nl/.) You should get the theme here -
so far it's the best theme I've seen!

4.04.2008

Scripting and the Terminal or How I DRYed up my Rails workflow and learned to love Ruby even more

As I work more and more on Rails projects I realize how many steps you have to go through just to start working.  Start the server, start the console, run autotest, open the project in TextMate and cd a terminal tab to your project directory to get ready for a little rake and generate action.  All this before I can write any code at all!  Of course this really isn't all that complicated with a combo of Terminal's history and Quicksilver you can accomplish all these tasks fairly quickly.  Although if you aren't paying attention Terminal's history can come back to bite you if you are working on several projects at once.  So yesterday I thought - there's got to be a better way.

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 ."
Each of the above in it's own tab in Terminal.
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
I'm a stickler for testing in multiple browsers.  So I've always got a few running at all times (now if I could find a way to script parallels to start XP and open an IE window also - I guess there is always version 2.)  Once the browsers were up and running it only makes sense that we would point them to the site we were working with - I mean if we are too lazy to open Terminal tabs ourselves then manually entering URL's is totally out of the question!  So of course the final steps would be:
  • 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...
Not too much there, looks like a pretty solid representation of the "getting started" process.  Just needs a "Open fridge, retrieve cold beer, bring beer to coffee table" command and I'd be set.

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