iChat Notification with Growl

So there you are doing your work and of course being the geeks that we all are you have about three hundred windows open, give or take a few hundred. Then the iChat icon starts bouncing…

Now you might be very organized and have the iChat window in a certain spot on the screen or even on a certain space in Spaces. You might be a whiz with Exposé and immediately find the right iChat window in the myriad of windows that are open. Or you might have one or two 27″ displays and not really care about this.

But for the rest us, wouldn’t it be nice if say a small window floated into the screen with a notification and the person who sent the message and maybe even the message? And it would have to be unobtrusive and float away just as quickly. You could glance at the notification and decide there and then wether it is necessary to dig out that iChat window.

Incidentally, this is what Growl really does well.

This window will float serenely in front of everything for a few seconds.

And with the scripting interface in iChat it is fairly simple to set up. After installing Growl, take this script:

property growlAppName : "Growl iChat"

property notificationNames : {"Buddy Became Available", ¬
	"Buddy Became Unavailable", ¬
	"Message Received", ¬
	"Completed File Transfer"}
property defaultNotificationNames : {"Buddy Became Available", ¬
	"Buddy Became Unavailable", ¬
	"Message Received", ¬
	"Completed File Transfer"}

using terms from application "iChat"

	on buddy became available theBuddy
		my registerWithGrowl()

		tell application "iChat"
			tell theBuddy
				set theTitle to full name & " became available"
				set theDesc to status message
				set theIcon to image
			end tell
		end tell
		my notify(theTitle, theDesc, theIcon, "Buddy Became Available")
	end buddy became available

	on buddy became unavailable theBuddy
		my registerWithGrowl()

		tell application "iChat"
			tell theBuddy
				set theTitle to full name & " went away"
				set theDesc to status message
				set theIcon to image
			end tell
		end tell
		my notify(theTitle, theDesc, theIcon, "Buddy Became Unavailable")
	end buddy became unavailable

	on message received theText from theBuddy for theTextChat
		my registerWithGrowl()

		tell application "iChat"
			set theIcon to image of theBuddy
			set theTitle to full name of theBuddy
		end tell
		my notify(theTitle, theText, theIcon, "Message Received")
	end message received

	on completed file transfer theTransfer
		my registerWithGrowl()
		tell application "iChat"
			tell theTransfer
				if transfer status is finished then
					if direction is incoming then
						set theTitle to "Received File "
						set theDesc to "from "
					else
						set theTitle to "Sent File "
						set theDesc to "to "
					end if

					set theTitle to theTitle & (file as string)
					set theDesc to theDesc & full name of buddy
				end if
			end tell
		end tell
		my notify(theTitle, theDesc, theIcon, "Message Received")
	end completed file transfer
end using terms from

on registerWithGrowl()
	tell application "GrowlHelperApp"
		register as application growlAppName all notifications notificationNames default notifications notificationNames icon of application "iChat"
	end tell
end registerWithGrowl

on notify(theTitle, desc, icondata, notificationName)
	tell application "GrowlHelperApp"
		if icondata is "" or icondata is missing value then
			notify with name notificationName title theTitle description desc application name growlAppName icon of application "iChat"
		else
			notify with name notificationName title theTitle description desc application name growlAppName image icondata
		end if
	end tell
end notify

Copy the code into AppleScript Editor and save the file as “Growl iChat” (as a script file) in ~/Library/Scripts/iChat/

In iChat, go to Preferences -> Alerts and select the Event “Message Received”, check “Run Applescript” and choose “Growl iChat.scpt”

I also setup the script to react to “Buddy Becomes Available,” “Buddy Becomes Unavailable” and “File Transfer Completed.” The great thing is that you don’t have to enable all notifications. You can even set it up individually so that you get notifications for some buddies, but not others. It should be easy to adapt the script to more actions if you wanted to.

Published by

ab

Mac Admin, Consultant, and Author

21 thoughts on “iChat Notification with Growl”

  1. Works like a charm! I’ve been missing the Growl notifications that Chax provided in Lion. This hint is an awesome replacement. Thanks!

  2. This is a super helpful hint, now that Chax no longer works with Lion. Thank you a ton for this! Do you think there is any way to tell Growl to show the buddy’s avatar in the notification, rather than the iChat logo? Thanks!

  3. Hi,
    thanks for your script, it was very useful when I switched to Lion.

    I even have a little modification I’d like to share: You can add a few lines to the script to display notifications only when iChat is in background, which i find very useful:

    tell application “System Events”
    if (name of the first process whose frontmost is true) is not “iChat” then
    –block to execute only when iChat is in background here
    end if
    end tell

    Just put this after “on …” and the second half before “end …”

    Best,
    Stefan

  4. Total AppleScript noob here. Is there a way to tweak this so that the notification only happens if iChat is in the background? It appears that the way it works now sends notifications even if iChat (and it’s chat window) is the active application/window.

    Thanks,

    – jim

  5. oh, thank you, man! you saved my life!!
    (exaggeration included)

  6. Looked forever for this functionality on OS X Lion. Someone on Twitter pointed me to the site. My joy cannot be contained, as I did not want to switch to AdiumX. iChat has pretty decent audio, video and screen sharing, which I use all the time.

    Now, if I could just get iChat to do Skype chats…

  7. THANK YOU THANK YOU THANK YOU!

    Seriously, this is great stuff…the lack of growl in iChat has been driving me crazy since I upgraded to Lion and chax stopped working. The only thing that would make this better is if you could bring iChat to the front when you click on the growl notification, but I can live without that.

    Thanks again!

  8. Hi,

    I am missing a small functionality of the script, and I don’t know how to implement it myself. The thing is that the growl notification window normally acts as a link to the message window, at least this was the functionality on Adium…

    Do you know how to add this??

  9. Thank you so much! I do not understand why Apple can not write or approve growl his uniform. (Translator Google)

  10. Hey, this is great! Do you mind if this gets distributed by other people? Also, can you think of an easy way for the script not to growl if iChat has the focus?

  11. Also:
    Absolutely beautiful!!!

    I also added:

    on chat room message received theText from theBuddy for theTextChat
    my registerWithGrowl()

    tell application “iChat”
    set theIcon to image of theBuddy
    set theTitle to full name of theBuddy
    end tell
    my notify(theTitle, theText, theIcon, “Message Received”)
    end chat room message received

  12. Thanks a lot for this post. Even if it’s rather old it is functioning quite good under lion too. I’ve tried to install chax, but this runs not under lion. Now my problem is solved in a very simple and elegant way.

  13. I LOVE using Growl for iChat – followed your instructions copied-and-pasted the script into AppleScript and saved it as a script in SCRIPTS/iChat folder – set iChat prefs to to run Growl iChat script…quit and relaunched iChat – AND got an error dialog box saying
    “An error occurred while executing an AppleScript event handler.
    Event: When I log in
    File: Growl iChat.ecpt
    Error: 1708.”

    HELP!

  14. Excellent and just what I was looking for.

    Runs perfectly with Growl 1.3.1, iChat 6.0.1 and Lion 10.7.2

    Good work fella!

  15. Thanks for the script! I modified it based on the code on the Growl site here http://growl.info/documentation/applescript-support#simpleNotificationSampleCode to run with their method of finding “GrowlHelperApp”:

    property growlAppName : “Growl iChat”

    property notificationNames : {“Buddy Became Available”, ¬
    “Buddy Became Unavailable”, ¬
    “Message Received”, ¬
    “Completed File Transfer”}
    property defaultNotificationNames : {“Buddy Became Available”, ¬
    “Buddy Became Unavailable”, ¬
    “Message Received”, ¬
    “Completed File Transfer”}

    using terms from application “iChat”

    on buddy became available theBuddy
    my registerWithGrowl()

    tell application “iChat”
    tell theBuddy
    set theTitle to full name & ” became available”
    set theDesc to status message
    set theIcon to image
    end tell
    end tell
    my notify(theTitle, theDesc, theIcon, “Buddy Became Available”)
    end buddy became available

    on buddy became unavailable theBuddy
    my registerWithGrowl()

    tell application “iChat”
    tell theBuddy
    set theTitle to full name & ” went away”
    set theDesc to status message
    set theIcon to image
    end tell
    end tell
    my notify(theTitle, theDesc, theIcon, “Buddy Became Unavailable”)
    end buddy became unavailable

    on message received theText from theBuddy for theTextChat
    my registerWithGrowl()

    tell application “iChat”
    set theIcon to image of theBuddy
    set theTitle to full name of theBuddy
    end tell
    my notify(theTitle, theText, theIcon, “Message Received”)
    end message received

    on completed file transfer theTransfer
    my registerWithGrowl()
    tell application “iChat”
    tell theTransfer
    if transfer status is finished then
    if direction is incoming then
    set theTitle to “Received File ”
    set theDesc to “from ”
    else
    set theTitle to “Sent File ”
    set theDesc to “to ”
    end if

    set theTitle to theTitle & (file as string)
    set theDesc to theDesc & full name of buddy
    end if
    end tell
    end tell
    my notify(theTitle, theDesc, theIcon, “Message Received”)
    end completed file transfer
    end using terms from

    on registerWithGrowl()
    tell application “System Events”
    set isRunning to ¬
    (count of (every process whose bundle identifier is “com.Growl.GrowlHelperApp”)) > 0
    end tell
    if isRunning then
    tell application id “com.Growl.GrowlHelperApp”
    register as application growlAppName all notifications notificationNames default notifications notificationNames icon of application “iChat”
    end tell
    end if

    end registerWithGrowl

    on notify(theTitle, desc, icondata, notificationName)
    tell application “System Events”
    set isRunning to ¬
    (count of (every process whose bundle identifier is “com.Growl.GrowlHelperApp”)) > 0
    end tell
    if isRunning then
    tell application id “com.Growl.GrowlHelperApp”

    if icondata is “” or icondata is missing value then
    notify with name notificationName title theTitle description desc application name growlAppName icon of application “iChat”
    else
    notify with name notificationName title theTitle description desc application name growlAppName image icondata
    end if
    end tell
    end if
    end notify

  16. Great script man I for one had to post and say how useful it is to finally have iChat notifications via Growl.

    Again thanks a lot for the script.

Comments are closed.