Thursday, September 04, 2008

iTerm AppleScript crashing fix

Lately, my officemate and I noticed that iTerm build 0.9.5.0902 crashes whenever AppleScript tries to talk to it. I was excited about some of the full screen fixes, but I couldn't do without my "Open iTerm Here" context menu item, and so I had to come up with a fix.

In my old scripts, I was doing things like this:
tell application "iTerm"
activate
set theTerm to make new terminal
tell theTerm
set theSession to make new session at the end of sessions
tell theSession to
exec command "/bin/bash -login"
write text "ls"
end tell
end tell
end tell
It appears like it's the make new session that's causing the problem. So I changed the set theSession... and tell theSession... lines to use a launch instead. The result:
tell application "iTerm"
activate
set theTerm to make new terminal
tell theTerm
launch session "Default Session"
tell the last session
exec command "/bin/bash -login"
write text "ls"
end tell
end tell
end tell
Not only does that not crash for me anymore, but it seems to be a bit faster (my imagination?).

No comments: