How do you set an Applescript as an action in Growl 2.1?

498 views
Skip to first unread message

dewshi

unread,
Aug 1, 2013, 1:53:28 PM8/1/13
to growld...@googlegroups.com
I'd like to run an applescript every time HardwareGrowler notifies that a Volume has mounted. Is this possible?

I see documentation of Applescript rules here: http://growl.info/documentation/applescript-rules, but I don't think this is what I need.

Does anyone have an example? Thanks.

Daniel Siemer

unread,
Aug 1, 2013, 9:17:14 PM8/1/13
to growld...@googlegroups.com
The folder where the scripts go the same as in those rules (Just don't name it Rules.scpt).  In your script you need an event handler:

using terms from application "Growl"

on perform action with notification

(* What you do with the notification goes in here*)

end perform action

end using terms from

Then open Growl's preferences, go to the displays tab, find the Script Action in the list, and select your script.  You may have to create a new configuration (the add config popup at the bottom).  Note that the script action changes its name in the list to the selected script.

William Brown

unread,
Aug 2, 2013, 8:19:04 PM8/2/13
to growld...@googlegroups.com
Could you post an example with more concrete terms and an actual example script. I don't know if notification is required, if it's a variable, etc. what sets it? does growl set it? is it the name of the notification sent by the application? etc. very confused. a simpler explanation with a concrete example would help a great deal.

Chris Forsythe

unread,
Aug 3, 2013, 11:54:12 AM8/3/13
to growld...@googlegroups.com
I'd suggest installing the bark plugin to use the notification-center bit here. Here's one pretty basic example though:


using terms from application "Growl"

on evaluate notification with notification

ignoring case

if notification's app name is "Dropbox" then

return {display:"notification-center"}

end if

if notification's app name is "Adium" then

return {display:"Music Video"}

end if

end ignoring

end evaluate notification

end using terms from


This is really basic though. You can do things like look at the contents of a notification, decide to not display something based on those contents, etc. We just don't have a repository of example scripts because we've only touched the surface of what's possible here. Scripting is one of the main reasons this release took a long time to get out and we still are just at the beginning of it. 

-- 
Chris Forsythe
--
You received this message because you are subscribed to the Google Groups "Growl Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to growldiscuss...@googlegroups.com.
To post to this group, send email to growld...@googlegroups.com.
Visit this group at http://groups.google.com/group/growldiscuss.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

William Brown

unread,
Aug 3, 2013, 12:54:09 PM8/3/13
to growld...@googlegroups.com
Hey, thanks for your help.
I'm looking to create a script that creates a bitly link to the file every time I upload a file using box simpleshare. the app copy's a url to the clipboard and sends a growl notification when it is done so I've written a script which will take the contents of the clipboard and check it is a url and then create a bitly link copy it to the clipboard and notify using growl. The script works succesfully the only thing is I want it to trigger every time box simpleshare sends a notification so that I automatically get a bitly link. I can't seem to get it to trigger.
What am I doing wrong?

-- this sub-routine is used to encode text 
on encode_text(this_text, encode_URL_A, encode_URL_B)
set the standard_characters to "abcdefghijklmnopqrstuvwxyz0123456789"
set the URL_A_chars to "$+!'/?;&@=#%><{}[]\"~`^\\|*:"
set the URL_B_chars to ".-_"
set the acceptable_characters to the standard_characters
if encode_URL_A is false then set the acceptable_characters to the acceptable_characters & the URL_A_chars
if encode_URL_B is false then set the acceptable_characters to the acceptable_characters & the URL_B_chars
set the encoded_text to ""
repeat with this_char in this_text
if this_char is in the acceptable_characters then
set the encoded_text to (the encoded_text & this_char)
else
set the encoded_text to (the encoded_text & encode_char(this_char)) as string
end if
end repeat
return the encoded_text
end encode_text

on encode_char(this_char)
set the ASCII_num to (the ASCII number this_char)
set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
set x to item ((ASCII_num div 16) + 1) of the hex_list
set y to item ((ASCII_num mod 16) + 1) of the hex_list
return ("%" & x & y) as string
end encode_char




using terms from application "Growl"
on perform action with notification
run

end perform action
end using terms from

on run
set Oauth to "*******" as string
set input to (the clipboard as string)
ignoring case
if (((characters 1 thru 4 of input) as string) is not equal to "http") then
set input to "http://" & input
end if
set theurl to encode_text(input, true, false)
set curlCMD to "curl --stderr /dev/null \"https://api-ssl.bitly.com/v3/shorten?access_token=" & Oauth & "&longUrl=" & theurl & "&format=txt\""
set shortURL to (do shell script curlCMD)
set the clipboard to shortURL
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"
-- Make a list of all the notification types 
-- that this script will ever send:
set the allNotificationsList to ¬
{"Success!"}
-- Make a list of the notifications 
-- that will be enabled by default.      
-- Those not enabled by default can be enabled later 
-- in the 'Applications' tab of the Growl preferences.
set the enabledNotificationsList to ¬
{"Success!"}
-- Register our script with growl.
-- You can optionally (as here) set a default icon 
-- for this script's notifications.
register as application ¬
"Box Bitly" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
-- icon of application "Script Editor"
--       Send a Notification...
notify with name ¬
"Success!" title ¬
"Success!" description ¬

"The Bitly link is " & shortURL application name "Box Bitly"

end tell

end if

end ignoring

end run

Message has been deleted

dewshi

unread,
Aug 6, 2013, 12:30:47 AM8/6/13
to growld...@googlegroups.com
OK, got it. Thanks Chris & Daniel.

Here's my example:




1. Save the following script as "test.scpt":

--test


using terms from application "Growl"

on perform action with notification

ignoring case

if notification's app name is "test growl" then

activate me

display dialog "goodbye" with icon 1

end if

end ignoring

end perform action

end using terms from




2. Drop it into ~/Library/Application Scripts/com.Growl.GrowlHelperApp (creating folder if necc)

3. Open Growl Prefs. You should see "test.scpt" in the list under Displays/Actions/ScriptAction

4. Choose ScriptAction from the drop down menu "Add Config". A duplicate of ScriptAction appears in Actions (???). Rename it "Test"

5. In the Applications tab, choose "test growl". Select "Test" from the "Actions" drop down menu.

That's it! Now run the "test growl" app.

Reply all
Reply to author
Forward
0 new messages