Can Someone Write an AppleScript for iChat?

The Growl forums have moved to Google Groups, this forum is read only.
User avatar
benjamindaines
Muffin
Posts: 45
Joined: Thu May 05, 2005 1:09 am

Can Someone Write an AppleScript for iChat?

Postby benjamindaines » Sun Sep 28, 2008 8:18 pm

I have an AppleScript (I'll attach it below) for iChat (set to run when buddies become available or unavailable under iChat's Alerts preferences) that puts up an alert whenever a buddy changes their status. The only thing missing from the iChat-Growl integration is an alert for messages received while iChat is not the foremost application like Adium has (shows the text of IMs received while other applications are on top of Adium). I was wondering, could anyone write a script to do this? I have absolutely no AppleScript skills. I'll attach the text of the script so you guys can see what's going on and hopefully figure out a way to do this.

--Thanks.

Code: Select all

property myNotifications : {budAvail:{title:"Buddy Available", action:" is available"}, budUnavail:{title:"Buddy Unavailable", action:" went away"}, invitation:{title:"Invitation", action:" invites you to chat"}, textInvite:{title:"Text Invitation", action:" wants to chat"}, audInvite:{title:"Audio Invitation", action:" wants to talk"}, vidInvite:{title:"Video Invitation", action:" invites you to a video chat"}, generic:{title:"Generic", action:""}}
property myAppName : "iChat"
property shouldInit : true

if shouldInit then init()

using terms from application "iChat"
   --on budAvail(bud)
   on buddy became available bud
      notify of (budAvail of myNotifications) by bud
   end buddy became available
   --end budAvail
   
   --on budUnavail(bud)
   on buddy became unavailable bud
      notify of (budUnavail of myNotifications) by bud
   end buddy became unavailable
   --end budUnavail
   
   on notify of notif by bud
      set uName to full name of bud
      --set uName to name of bud
      set msg to uName & (action of notif)
      set img to a reference to image of bud
      growl(title of notif, msg, image of bud)
   end notify
end using terms from

on growl(notif, descr, img)
   tell application "GrowlHelperApp"
      try
         notify with name notif ¬
            title notif ¬
            description descr ¬
            application name myAppName ¬
            image img
      on error
         notify with name notif ¬
            title notif ¬
            description descr ¬
            application name myAppName
      end try
   end tell
end growl

on init()
   set shouldInit to false
   set myNotificationList to {}
   repeat with bar in myNotifications as list
      copy title of bar to end of myNotificationList
   end repeat
   
   tell application "System Events"
      if (count of (every process whose name is "GrowlHelperApp")) > 0 then
         tell application "GrowlHelperApp"
            register as application ¬
               myAppName all notifications myNotificationList ¬
               default notifications myNotificationList ¬
               icon of application myAppName
         end tell
      end if
   end tell
end init

User avatar
Diggory
Growl Team
Posts: 129
Joined: Sat Dec 04, 2004 12:17 pm
Location: London

Re: Can Someone Write an AppleScript for iChat?

Postby Diggory » Mon Sep 29, 2008 2:17 pm

As far as I can tell, the text of the incoming message is not available via scripting so you can't growl 'foo said "Hello!" ', but you can have 'foo sent you a message'

Which this modified version of the script does - you will have to attach it to the 'message received' action.

Code: Select all

property myNotifications : {budAvail:{title:"Buddy Available", action:" is available"}, budUnavail:{title:"Buddy Unavailable", action:" went away"}, invitation:{title:"Invitation", action:" invites you to chat"}, textInvite:{title:"Text Invitation", action:" wants to chat"}, audInvite:{title:"Audio Invitation", action:" wants to talk"}, vidInvite:{title:"Video Invitation", action:" invites you to a video chat"}, messageReceived:{title:"Message Received", action:" sent you a message"}, generic:{title:"Generic", action:""}}
property myAppName : "iChat"
property shouldInit : true

if shouldInit then init()

using terms from application "iChat"
   --on budAvail(bud)
   on buddy became available bud
      -- mylog("buddy avail")
      notify of (budAvail of myNotifications) by bud
   end buddy became available
   --end budAvail
   
   --on budUnavail(bud)
   on buddy became unavailable bud
      -- mylog("buddy unavail")
      notify of (budUnavail of myNotifications) by bud
   end buddy became unavailable
   --end budUnavail
   
   
   on message received theText from bud for theTextChat
      if (frontmost of application "iChat" is false) then
         -- mylog("message received")
         notify of (messageReceived of myNotifications) by bud
      end if
   end message received
   
   
   on notify of notif by bud
      set uName to full name of bud
      --set uName to name of bud
      set msg to uName & (action of notif)
      set img to a reference to image of bud
      --      mylog("notif " & msg)
      growl(title of notif, msg, image of bud)
   end notify
end using terms from

on growl(notif, descr, img)
   tell application "GrowlHelperApp"
      try
         notify with name notif ¬
            title notif ¬
            description descr ¬
            application name myAppName ¬
            image img
      on error
         notify with name notif ¬
            title notif ¬
            description descr ¬
            application name myAppName
      end try
   end tell
end growl

on init()
   -- mylog("initing")
   set shouldInit to false
   set myNotificationList to {}
   repeat with bar in myNotifications as list
      copy title of bar to end of myNotificationList
   end repeat
   
   tell application "System Events"
      if (count of (every process whose name is "GrowlHelperApp")) > 0 then
         tell application "GrowlHelperApp"
   --         mylog("registering ichat with growl")
            
            register as application ¬
               myAppName all notifications myNotificationList ¬
               default notifications myNotificationList ¬
               icon of application myAppName
         end tell
      end if
   end tell
end init

on mylog(loggingtext)
   do shell script "logger -s -t growlIchat " & loggingtext
end mylog

User avatar
Diggory
Growl Team
Posts: 129
Joined: Sat Dec 04, 2004 12:17 pm
Location: London

Re: Can Someone Write an AppleScript for iChat?

Postby Diggory » Wed Oct 01, 2008 11:54 pm

Did that help at all?

User avatar
benjamindaines
Muffin
Posts: 45
Joined: Thu May 05, 2005 1:09 am

Re: Can Someone Write an AppleScript for iChat?

Postby benjamindaines » Thu Oct 02, 2008 12:08 am

Diggory wrote:Did that help at all?

Yes thanks. It doesn't work quite as well as Adium, but it works well enough :)

meatleg
Harmless
Posts: 10
Joined: Tue Mar 07, 2006 4:49 pm

Re: Can Someone Write an AppleScript for iChat?

Postby meatleg » Thu Oct 02, 2008 3:13 am

if you use Growl iChat, then growl will give you the messages that you receive in a growl window.... if that is what you were looking for. you can choose to see messages from all users or just one user.
http://growlichat.com/download.php

dirtbiketrailsrider
Harmless
Posts: 1
Joined: Mon Jun 29, 2009 8:57 pm

Re: Can Someone Write an AppleScript for iChat?

Postby dirtbiketrailsrider » Mon Jun 29, 2009 9:00 pm

Hi, I am pretty new to the applescript world and I was wondering how iChat knows to run this script when a message is received from another user. I am trying to modify this script so when a certain user sends a message a custom sounds will play. Thanks for any help.


Return to “Growl”

Who is online

Users browsing this forum: Majestic-12 [Bot]