Friday, September 09, 2011

UPDATE: This script has been improved; the new version is now on github.
UPDATE 2: Growl 1.3 was just released, so I've updated the script to work with 1.3. If you were using this script and it broke with 1.3, then just download the updated version from the same place. If you're still using Growl 1.2.2, you'll need to use the old version of this script. All the rest of the instructions are the same regardless of which version of Growl you're using.

Lion is the latest version of OS X. iChat is the chat program that's part of OS X. Growl is a system that lets all sorts of programs post little notification windows on your screen.

For example, if you get a message in iChat while you're in another window, it's nice to have the message pop up on your screen so you can decide whether or not to switch windows to read it. Or if a buddy logs in, it's nice to know about that (which can be done in iChat with an audio notification), and see who it is without having to check your buddy list.

I used to use Chax for this. Chax is a pretty good program, but when a new version of OS X comes out, it takes a little while to catch up. The main reasons I use Chax are:

Accept text chat invitations without being prompted.

Put all my buddies in the same window.

Give me Growl notifications.

Everything but the Growl feature is now built into iChat in Lion. (The auto-accept is an AppleScript that ships with Lion; you can turn that on in Preferences:Alerts. The option for "Show all my accounts in one list" is in Preferences:General.)

Chax isn't yet compatible with Lion, so I searched online and found a little AppleScript program to do a bit of what I need. Using the ideas from that, I expanded it a bit. Goodbye Chax; I'll miss you!

Save it to your home directory's Library:Scripts:iChat folder. (I used the filename "Growl".) The iChat folder might not exist; you need to create it. By default, your Library folder is hidden. (Personally, I solved that by saving to the desktop, and then I ran "open ~/Library/Scripts" in Terminal so that the Scripts window opened in Finder, and dragged my script there.)

In iChat, open the Preferences.

Under Alerts, select the "Message Received" event.

Turn on "Run an AppleScript script:", and select the script you saved earlier.

Repeat the last two steps for each event you're interested in.

Note that the "Message Received in Chat Room" (which is called "addressed message received" in the AppleScript) and "Invitation to Share Buddy's Screen" (a.k.a. "received remote screen sharing invitation") aren't currently enabled, since it looks like there may be a bug in iChat that will cause them to be confused with each other.

If you use the Growl script for chat invitations, you can't also use the Auto-Accept script, since you can only select one script to be run. Because of this, I've added an auto-accept capability to this Growl script. By default, it's turned off, but you can turn it on. Near the top of the program, there's a line that says:

@Anonymous: If "Login Finished" is the only notification that you get, then you probably didn't set the AppleScript to run for the other events. In iChat's Preferences, under "Alerts", select each event you want individually, and turn on the "Run an AppleScript script" and set the script for each of them. In other words, select "Buddy Becomes Available", turn on "Run an AppleScript script", set the script to your script, then select the event "Buddy Becomes Unavailable", turn on "Run an Applescript script", set the script to your script, and so on for each event you care about.

@Anonymous: I'm not sure what might be causing the GrowlHelperApp error. Are you using the latest version of Growl (1.2.2; I haven't tested with 1.3-prerelease)? Not to sound insulting, but is it turned on in its System Preferences pane? Is Growl working with any other apps?

Hey there! First of all great work and thanks. I have some questions though. 1. Is there a way to not show "Buddy is available" right after logon? it's a little annoying to have all the popups come up when logging into iChat. And 2. Is it possible to have it differentiate between unavailable, inactive and offline, like Chax used to before iChat 6/Lion? This would make the script complete and perfect for me.

Could you implement that iChat-Windows gets in focus (Apple Script -> tell Application iChat to activate) when you click on the Growlnotification? I don't know how to use the on click-handler in Growl.

@postglock: Hmmm, it sounds like Growl isn't installed, or a different version of Growl than was expected. Did you have a message asking you to help AppleScript Editor find Growl?

If Growl 1.3 is installed, then please file an issue at https://github.com/Piquan/iChat-Growl/issues and we can work through this problem there. If you have Growl 1.2.2, then change the line tell application "Growl" to tell application "GrowlHelperApp" (as described in the comment just above that line). If you don't have Growl installed, then you need to install it before you can use this script.

Ah, you have to let AppleScript Editor know about the Growl library first. In AppleScript Editor, go to the menu Window > Library, then click the + button, and select Growl. It should compile fine now. Thanks for the code!Also, auto-accept isn't working for me either, whereas the Apple-included script works fine. I'll have more of a play later tonight and see if I can find the problem.

Sorry, I posted before I read your reply. Oddly enough, AppleScript Editor wasn't fussed by the 'tell application "Growl"' line, but only the later reference. Anyway, it's all good now.

I also worked out my problem with auto-accept. I misread your instructions and installed the script into ~/Library/Scripts/Applications/iChat/ (where you place scripts that are accessible from the AppleScript menubar icon). I turned out that when I selected this script via the file browser in iChat, it created a copy in ~/Library/Scripts/iChat/ . Hence the problem was that iChat was reading the old version of the script.

@Anonymous: If you want to see Growl notifications even when you're chatting with that buddy, then look for the comment that says "-- Don't do anything if we're chatting with the buddy in question" (line 28 in the current version). Right under that comment is a line that says "try". Ten lines later is "end try". Remove everything between (and including) the "try" and the "end try".

-- Don't do anything if we're chatting with the buddy in question try local frontApp, windowName -- This is in a "try" because, if things aren't exactly as we're expecting (e.g., iChat is frontmost but has no windows open), we want to go ahead and growl. tell application "System Events" to set frontApp to name of first application process whose frontmost is true if frontApp is "iChat" then tell application "iChat" to set windowName to name of front window -- Character id 8212 is an em dash. We don't use a literal, because AppleScript uses Mac-Roman or UTF-16 (with a BOM), but github will show it as ISO-8859-1. To allow both clones and web browsing to work, we use ASCII only. if windowName starts with (buddyName & space & character id 8212 & space) then return if windowName ends with (space & character id 8212 & space & buddyName) then return end if end try

@Anonymous: Hmmm, that's like the right bit to remove. If it's still showing notifications if and only if you're in a different window, then perhaps iChat didn't see your change. Make sure that you saved it to the right place, and with file format "script". Also go back and make sure that the right script is still selected in iChat's preferences; if you saved an old version by renaming it, the iChat preferences may have followed the renamed version instead of the new one you created.

If that doesn't fix your problem, then let's finish this conversation at github instead. Go to https://github.com/Piquan/iChat-Growl/issues/new and file an issue. (You'll need a github account, but it's a quick signup, and the free account will be fine.)

Just a quick note, when I use the script to notify me of account log offs, and I log off of one of my two accounts (Jabber+AIM), then the Growl logoff notification appears twice. Completely minor, but just thought I'd point it out.