Saturday, 17 August 2013

Run Applescript with Growl 2.1 Rules

Run Applescript with Growl 2.1 Rules

Currently, I have a flow set up that results in a file -- 'cb.txt' --
being added to my Dropbox. I get a Growl notification with the Application
Name 'Dropbox' and the Note Title 'cb.txt added'. I want the 'cb.txt
added' notification to run an applescript that will copy the text from
cb.txt to my clipboard. The rules for Growl's notification can be found
here.
Here is the applescript I want to run (when I run it by itself via
Applescript, it successfully adds the contents of cb.txt to the
clipboard):
set the_file to "HardDrive:Users:Me:Dropbox:Folder:cb.txt"
set the_text to (do shell script "cat " & quoted form of (POSIX path of
the_file))
set the clipboard to the_text
I have saved this file to ~/Library/Application
Scripts/com.Growl.GrowlHelperApp as an apple script. I have also saved
another version using this code:
using terms from application "Growl"
on perform action with notification
ignoring case
if notification's app name is Dropbox then
if notification's note title contains "cb.txt added" then
set the_file to "Macintosh
HD:Users:Caleb:Dropbox:Apps:CBApp:cb.txt"
set the_text to (do shell script "cat " & quoted form
of (POSIX path of the_file))
set the clipboard to the_text
end if
end if
end ignoring
end perform action
end using terms from
The previous script does not do anything when run. I have this saved as
Rules.scpt:
using terms from application "Growl"
on evaluate notification with notification
--Rules go in here
--Ultimately return what you want Growl to do with the notification
end evaluate notification
end using terms from
Obviously, I'm a bit stuck. If anybody could give me advice on how to get
my working applescript code to run when I receive a specific Growl
notification, I would appreciate it!

No comments:

Post a Comment