Quicksilver rails project opener (revisited)

16 01 2008

I’ve switched my terminal over from Terminal to iTerm and my subversion client from SVNX to ZigVersion. So I re-wrote my opener for these new apps. Installation and such should be the same as the original.

#!/usr/bin/env ruby

#####################################################################
# This script will load all the common applications used for
# developing rails. It may be triggered by quicksilver or console.
# The full path of the project to open should be the first argument.
#
# FixMe: If iTerm is not open an unwanted window is created
#
# Applications that will be loaded:
#   Textmate at project
#   Projects mongrel server
#   Projects rails console
#   Blank console in project dir
#   Firefox at project
#   ZigVersion
#####################################################################

# Load files required for appscrpt
require "rubygems"
require "appscript"
include Appscript

# Define arrays and grab project path
tabs    = []
threads = []
project = ARGV[0]
# project = "~/Programming/rails/code_library"

# Do iterm stuff in one thread
threads << Thread.new do
  # Make a new iTerm window
  window = Appscript::app('iTerm').end.make(:new=>:terminal)

  # Create three new tabs and store in sessions array
  3.times do
    window.launch_(:session => 'default')
    tabs << window.sessions.last.get
  end

  # Change each tab to project path
  tabs.each { |tab| tab.write(:text => "cd #{project}") }

  # Start textmate, server and console from tabs
  tabs[0].write(:text => "mate ."         )
  tabs[1].write(:text => "script/server"  )
  tabs[2].write(:text => "script/console" )
end

# Open ZigVersion and Firefox, each in their own thread
threads << Thread.new { Appscript::app("Firefox").OpenURL("http://localhost:3000") }
threads << Thread.new { Appscript::app('ZigVersion').activate                      }

# Join threads together to stop premature termination
threads.each { |thread| thread.join }
Advertisements