Thursday, February 2, 2012

Applescript to set up sessions in iTerm for a rails project.

If you are like me, every time you start work on your rails project, you go through the same motions to get ready. Lets say the project is called "sequin". Here are the steps.

* Open bash sessions in 5 tabs in iTerm all with different color backgrounds.
* In each shell, cd to ~/dev/sequin, then run rvm use 1.9.2-p290@sequin (because there is already a gemset called sequin for this project).
* Then in the first shell, start the thin server.
* In the second shell, start a rails console.
* The third shell is for running tests.
* In the forth shell, run "mate ." to open the project in TextMate.
* The fifth shell is listening to the development log.
* Tabs are renamed: server, console, test, shell, log respectively.

That's a lot of effort, so I wrote these applescripts. You'll have to substitute sequin for the name of your project of course.

In ~/Library/Application\ Support/iTerm make the directories: include and Scripts.

You'll have to open these scripts in the applescript editor and save as script in the locations specified.

Save rails_shells.scpt into "include"


Save sequin.scpt into Scripts


To make it work, you have to have set up a gemset with:
> rvm gemset create sequin.
And add an alias in your bashrc that will cd to the project directory and set the environment to your gemset as in the gist .bashrc below.


Now when you next open iTerm the script sequin will appear in the Scripts menu.

You could of course change directory and set the gemset explicitly in the applescript. I just like to have that alias available.