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




Quicksilver Action : Open Rails Project

6 01 2008

I’ve been doing tonnes of rails coding lately and absolutely loving it! I noticed that my work flow wasn’t all that DRY though; Every time I start working on an app I open up the same stuff:

  • The app as a project in Textmate (mate .)
  • The app server (script/server)
  • The app console (script/console)
  • A blank terminal (sc… wait.. no)
  • Firefox (http://localhost:3000/)

So I wrote a quicksilver action that does it all for me!

#!/usr/bin/env ruby

require "rubygems"
require "appscript"
include Appscript

# Grab the project location from the command line / quicksilver
project = ARGV[0]

# Initialize variables
term = app("Terminal")
ff   = app("Firefox")
threads = []

# Activate terminal and firefox
# This will open a new window if the app was not already
# open, which can result in one too many windows
term1 = term.activate

# So we'll close the first window if there is one
term.windows[0].close unless term.windows.get.to_s == ""

# Open up a terminal window at the project.
# Then open the project in textmate from
# the terminal, all in it's own thread
threads << Thread.new do
  term3 = term.do_script("cd " + project)
  term.do_script("mate .", :in => term3)
end

threads << Thread.new do
  term1 = term.do_script("cd " + project)
  term.do_script("script/server", :in => term1)
end

threads << Thread.new do
  term2 = term.do_script("cd " + project)
  term.do_script("script/console", :in => term2)
end

threads << Thread.new do
  ff.OpenURL("http://localhost:3000")
end

# Join all of the threads to the main one
# This stops the script exiting before all
# threads have finished
threads.each do |thread|
  thread.join
end

To Install:

  • Install the appscript gem with “gem install rb-appscript”
  • Copy script to “~/Library/Application Support/Quicksilver/Actions/Open Rails Project.rb” (you’ll need to create the file)
  • Restart quicksilver

To Use:

  • Use Quicksilver to navigate to your project folder
  • Select “Open Rails Project” as the action.

Enjoy!