I have the following applescript. I have it set to run in ichat when i recieve an IM. It notifies me via growl of new messages:
on notify_growl(theName, theTitle, theDescription, theImage)
display dialog theImage
tell application "Growl"
notify with name theName title theTitle description theDescription application name "iChat" image theImage
end tell
end notify_growl
using terms from application "iChat"
-- register the app with growl
tell application "Growl"
set the allNotificationsList to {"Message Received"}
set the enabledNotificationsList to {"Message Received"}
register as application "iChat" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "iChat"
end tell
-- handle the iChat events
on message received theMessage from theBuddy for theChat
if ((application "iChat" is not frontmost) or (status of application "iChat" is equal to away)) then
notify_growl("Message Received", name of theBuddy, theMessage, image of theBuddy)
end if
end message received
on received text invitation theMessage from theBuddy for theChat
accept theChat
if ((application "iChat" is not frontmost) or (status of application "iChat" is equal to away)) then
notify_growl("Message Received", name of theBuddy, theMessage, image of theBuddy)
end if
end received text invitation
end using terms from
The issue is that if my buddy doesn't have an image associated, I get an error. So I want to add an if statement in notify_growl where if theImage is blank, or null, or whatever, to growl sans the image. The display dialog theImage, when empty shows a dialog that says "msng"
Test against
missing value
, AppleScript's analogue of a null/undefined value. In your case, that would look something like the following if you want to just leave out the image:If you instead had a default image, you could write
For a default image, you could do something like this:
There may be an easier way, but this will get you an image. However, it's sufficiently slow that it might not work in your case.