Friday, September 09, 2011

iChat, Growl, and Lion

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:
  1. Accept text chat invitations without being prompted.
  2. Put all my buddies in the same window.
  3. 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!

To use this:
  1. Install Growl, if you don't have it already.
  2. Visit https://github.com/Piquan/iChat-Growl/raw/master/Growl.applescript in your web browser.  (You can use the formatted page instead.)
  3. Open AppleScript Editor (in Applications:Utilities).
  4. Copy and paste the code from the web page into a new script.
  5. 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.)
  6. In iChat, open the Preferences.
  7. Under Alerts, select the "Message Received" event.
  8. Turn on "Run an AppleScript script:", and select the script you saved earlier.
  9. 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:

        property autoAccept : {""}

Change this to:

        property autoAccept : {"text"}

Suggestions for improvements are welcome.  Share and enjoy!

(If you expected the source code to be here in my blog, I've moved it.  See https://github.com/Piquan/iChat-Growl/raw/master/Growl.applescript for my latest version.)

33 comments:

Anonymous said...

Awesome! Just what I've been looking for, or hoping Chax would be updated. This seems to work perfectly.

Thanks!

Anonymous said...

perfect... nice work sir!! Just what I was looking for :)

Anonymous said...

The only notification that works is the login finished! I can;t understand why! Please i would appreciate if you could help!

Piquan said...

@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 said...

Everything works fine instead of the autoaccept feature! Something is wrong but i can't find it! Please do something!

Piquan said...

Normally, auto accept is disabled. You need to change one line in the program to enable it. Read the last part of my post again. If you're still having problems, please file an issue at github.

Anonymous said...

Oh how I was looking forward to this. I'm getting the following though:

"An error occurred while executing an AppleScript event handler.

Event: Message Received
File: ichat-growl.scpt
Error: GrowlHelperApp got an error: Connection is invalid
"

I'm using ichat with jabber connection to google. Not sure what to do to fix this.

Piquan said...

@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?

Piquan said...

Growl 1.3 was released today, and a user saw that it's not compatible with this script. It's an easy fix, though; I've put the new version up in the same place.

Anonymous said...

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.

Piquan said...

@Anonymous: Both are features I've been thinking of implementing, since I have the same frustrations, but haven't gotten the time to put into it. I believe that both are possible, though.

Florian Henning said...

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.

Thank you :)

PS: The Script is great!

Piquan said...

@Florian: I wish that I could. Unfortunately, Growl doesn't provide that ability to AppleScript; you can only get click notifications if you're using the Objective C interface.

Anonymous said...

Thanks! Working great.

postglock said...

I'm trying to compile this in AppleScript Editor, but I get a Syntax Error:
Expected end of line, etc. but found """.

The quotation mark selected by AppleScript Editor is the first one in the line beginning:
register as application "

Piquan said...

@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.

postglock said...

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.

postglock said...

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.

Cheers again!

Anonymous said...

What do I need to take out of the script in order to have it popup even if the window is active?

Piquan said...

@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".

Anonymous said...

Hmmm... that didn't work for me. Here's what I deleted:


-- 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

Piquan said...

@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.)

Anonymous said...

Thanks a lot :)
Works great in Growl 1.2/OS X 10.7.2

Anonymous said...

Is it possible to change the style that growl is using ?
Thanks !

Anonymous said...

Yep! Awesome. Thanks man.

Piquan said...

@Anonymous: You can change the Growl style within Growl: run Growl (within Applications), and select the Displays tab. You can learn more about how to customize Growl at http://growl.info/

Anonymous said...

Thx alot dude! Much appriciated.

James Coulee said...

I found an "Auto-Resize buddy list" applescript, if you guys find it useful..

http://tiagodovale.deviantart.com/art/Chax-alternative-for-iChat-Growl-and-Auto-Resize-284084652

Anonymous said...

Perfect just what I was looking for!

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.

Using Growl 1.2.2 on OSX 10.7.3

Anonymous said...

Simply awesome!

from Germany said...

Thanks!!
now i can delete Adium :-)
Growl with iChat, love it!!!

James Coulee said...

There's a version for Messages Beta:
http://tiagodovale.deviantart.com/art/Growl-AutoResize-for-MESSAGES-Beta-285399682

Shanon said...

Hey this has almost exactly what I need. Do you think it would be possible to add something to the code that notifies you when a keyword is posted in chat rooms?