Saturday, March 14, 2009

iChat Event Handling (Error 1708)


If you google for 1708 you'll find a bazillion pages with people complaining about Error 1708 in connection mostly with AppleScript, and especially with iChat. The gist of the error is "I sent an AppleEvent (how AppleScript makes applications do stuff) and it wasn't handled".

When an application like iChat runs an AppleScript it can trigger specific code by passing it an event, instead of just running the whole script which would force you divide all of your code into tiny little scripts based on which event triggers them (which most people do, but the 'advanced' option is nice to have). Sometimes the script in question doesn't have a 'handler' for the that type of event, like in our case "On Login Finished". Normally this is handled gracefully, the script as a whole runs, and the user never notices. But in the recent builds of iChat it instead presents a fairly nasty error message to the user.

There's a workaround used in a few applescripts dealing with iChat (but googling for this workaround with 1708 is obscured by all the other posts), here's one. You have to explicitly handle the event iChat sends you when it runs your script, and instead of using a "tell" you just "use terms from" and all actions implicitly apply to the calling application (iChat).

Someone might find this interesting, and someone might find this in google when they have the same problem. Here's my script (.scpt file) for setting location based on Wifi SSID.

2 comments:

Graham said...

Wow, thank you so much. I was about to go crazy with this one.

Lake said...

Thanks for the comment. After more than a year this blog post has been validated =)