Question

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!

Was it helpful?

Solution

You can use app name but if you do not put quotes around a string the it is seen as a variable.

If the variable is not declared before you try and access it/use it you will get an error.

This is what is happening to you. You can see this in the Consol.app

18/08/2013 11:46:11.961 Growl[89225]: completion error: Error Domain=NSPOSIXErrorDomain Code=2 "The operation couldn’t be completed.... .../Library/Application Scripts/com.Growl.GrowlHelperApp/Rules.scpt: execution error: The variable Dropbox is not defined. (-2753) }

Putting the string Dropbox in quotes will fix this.

Here is a working test I used.

    using terms from application "Growl"

    on evaluate notification with notification

        if notification's app name contains "Image File" then
            if notification's note title contains "jpeg Error" then
                do shell script "echo " & quoted form of note type of notification & " >  ~/notification.txt "

            end if
        end if


        if notification's app name is "Dropbox" then

        if notification's note title contains "cb" then
            set the_file to ("cb.txt") as string
            set the_text to (do shell script "cat ~/Dropbox/" & quoted form of the_file)
            set the clipboard to the_text
            do shell script "echo " & quoted form of the_text & " >  ~/dbnotification.txt "
        end if
    end if
    end evaluate notification
end using terms from

This also shows you how to test for different rules

NOTE** Normally I would get the users home folder with:

set homePath to (path to home folder from user domain) as text 

But there seems to be a bug in growl that returns a growl folder

com.Growl.GrowlHelperApp/Rules.scpt: execution error: cat: /Users/USERNAME/Library/Containers/com.Growl.GrowlHelperApp/Data/Dropbox/cb.txt: No such file or directory (1)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top