CODING WITH CUTLERY

It's dangeresque.

Shortening Daily Boot Time With iTerm2 and AppleScript

| Comments

Last week, it struck me that I spend a significant amount of time at the beginning of each day bootstrapping my work environment. I usually launch iTerm2 (my favorite Mac OS X Terminal replacement), type several commands, open some TextMate projects, start some Rails servers and on and on. Sounds like a job for automation!

Fortunately, iTerm2 comes with fairly good AppleScript support right out of the box. You can open new terminal windows and tabs, set properties on each and issue commands, among other things. Though it’s not perfect (for instance, you can’t yet easily open split panes), it’s enough to get one started down the road to workday automation nirvana.

Without further ado, here’s my current work environment script:

start_workday.applescript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
tell application "iTerm"
	activate
	
	set myterm to (make new terminal)
	tell myterm
		set number of columns to 175
		set number of rows to 50
		
		-- Open first project tab.
		set hm_session to (launch session "Open to HM project")
		delay 5
		tell hm_session
			write text "mate ."
			write text "rails s"
		end tell
		
		-- Open second project tab.
		set hm_old_session to (launch session "Open to HM project (old)")
		delay 5
		tell hm_old_session
			write text "mate ."
			write text "rails s --port 3001"
		end tell
		
		-- Open tab for blog (I use Octopress).
		set blog_session to (launch session "Open to blog")
		delay 5
		tell blog_session
			write text "mate ."
			write text "rake watch"
		end tell
		
		-- Open a vertical pane on each tab, ending up back on the first.
		tell i term application "iTerm" to activate
		tell i term application "System Events"
		  key code 19 using command down
		  keystroke "d" using command down
		  key code 20 using command down
		  keystroke "d" using command down
		  key code 18 using command down
		  keystroke "d" using command down
		end tell
	end tell
end tell

For more AppleScript + iTerm2 goodness, check out this post by Samantha Halfon.

Also, I was able to find a decent AppleScript key code reference.

Happy automating!

EDIT: Altentee has written a helpful article on this subject with another sample work environment script.

Starting Over

| Comments

Considering I’ve decided to change directions in my career from doing mainly .NET and legacy C++ application development to web and mobile development with Rails, JavaScript and soon Objective-C (iOS) and Java (Android), I figured it’s time to start a little interwebs place where I can explore these topics in great big detail.

I was recently introduced to Octopress by some of my dev buddies and I’ve decided to give it a try. I love the idea of static site generation. Already I feel more excited about blogging than during any of my previous attempts. Besides, there’s plenty to blog about in the web world, so let’s hope I’ll get with it.

To motivate myself, I’ve written a small program. With this one-liner, I’ve discovered a proven technique to secure a successful blogging future:

This Works–Try It! - blag.rb
1
puts "Blog!" unless lazy or busy

My good friend irb gives the following output:

1
2
3
4
5
ruby-1.9.2-p290 :001 > puts "Blag!" unless lazy
NameError: undefined local variable or method `lazy' for main:Object
        from (irb):1
        from /Users/facto/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'
ruby-1.9.2-p290 :002 >

I simply have no excuse. You see, in Ruby, such nonsense as ‘lazy’ and ‘busy’ passes no muster. 1


  1. Please don’t notify me that the reason I’m getting this error is because I haven’t defined the variables ‘lazy’ or ‘busy’. I have very little time as it is.