Page 1 of 1

osascript & Growl

Posted: Mon Jun 02, 2008 9:21 pm
by wordtech
I'm trying to put together an AppleScript to post Growl notifications that I can call from the command line. The idea is to call the script in this fashion: "osascript macgrowl.applescript AppName Title Description". The script below has no errors that I can identify--it compiles fine in Script Editor and returns no error messages in the Terminal--but it doesn't post any notifications. Can someone take a look at it and give me any suggestions as to what I'm doing wrong? TIA.

--macgrowl.applescript: call from command line via osascript macgrowl.applescript AppName Title Description

property theAppName : {}
property theTitleString : {}
property theGrowlString : {}

on run args
checkGrowl()
set theAppName to item 1 of args
set theTitleString to item 2 of args
set theGrowlString to item 3 of args
runGrowl()
end run


on checkGrowl()
tell application "System Events"
set isRunning to ¬
(count of (every process whose name is "GrowlHelperApp")) > 0
if isRunning = 0 then
return "Growl is not installed."
end if
end tell
end checkGrowl

on runGrowl()

tell application "GrowlHelperApp"
-- Make a list of all the notification types
-- that this script will ever send:
set theNotification to {theAppName & " Notification"}

-- Register our script with growl.
-- You can optionally (as here) set a default icon
-- for this script's notifications.
register as application theAppName ¬
all notifications theNotification ¬
default notifications theNotification ¬
icon of application theAppName

-- Send a Notification...
notify with name theNotification ¬
title theTitleString ¬
description theGrowlString ¬
application name theAppName
end tell
end runGrowl

Re: osascript & Growl

Posted: Tue Jun 03, 2008 12:44 am
by wordtech
Got it working. I didn't correctly parse the list of notifications to get the right one. Here's what I came up with:

property theAppName : {}
property theTitleString : {}
property theGrowlString : {}


on run args
checkGrowl()
set theAppName to item 1 of args
set theTitleString to item 2 of args
set theGrowlString to item 3 of args
runGrowl()
end run


on checkGrowl() -- check to make sure Growl is installed
tell application "System Events"
set isRunning to ¬
(count of (every process whose name is "GrowlHelperApp")) > 0
if isRunning = 0 then
return "Growl is not installed."
end if
end tell
end checkGrowl

on runGrowl()

tell application "GrowlHelperApp"
-- Make a list of all the notification types
-- that this script will ever send:

set the theNotification to ¬
{"MacGrowl Notification"}

-- Register our script with growl.
-- You can optionally (as here) set a default icon
-- for this script's notifications.
register as application theAppName ¬
all notifications theNotification ¬
default notifications theNotification ¬
icon of application theAppName

-- Send a Notification...
notify with name ¬
(item 1 of theNotification) title theTitleString ¬
description theGrowlString ¬
application name theAppName
end tell
end runGrowl