1

目前,我设置了一个流程,该流程会导致一个文件——“cb.txt”——被添加到我的 Dropbox 中。我收到一条 Growl 通知,其中包含应用程序名称“Dropbox”和注释标题“cb.txt added”。我希望'cb.txt added'通知运行一个applescript,它将文本从cb.txt复制到我的剪贴板。Growl 的通知规则可以在这里找到。

这是我要运行的applescript(当我通过Applescript自行运行它时,它成功地将cb.txt的内容添加到剪贴板):

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

我已将此文件保存~/Library/Application Scripts/com.Growl.GrowlHelperApp为苹果脚本。我还使用此代码保存了另一个版本:

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

前面的脚本在运行时不执行任何操作。我将其保存为 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

显然,我有点卡住了。如果有人可以就如何在我收到特定的 Growl 通知时运行我的工作 Applescript 代码提供建议,我将不胜感激!

4

1 回答 1

0

您可以使用应用程序名称,但如果您不在字符串周围加上引号,则它被视为变量。

如果在您尝试访问/使用它之前未声明该变量,您将收到错误消息。

这就是发生在你身上的事情。您可以在 Consol.app 中看到这一点

2013 年 8 月 18 日 11:46:11.961 Growl [89225]:完成错误:错误域 = NSPOSIXErrorDomain 代码 = 2“操作无法完成.... .../Library/Application Scripts/com.Growl。 GrowlHelperApp/Rules.scpt:执行错误:未定义变量 Dropbox。(-2753) }

将字符串 Dropbox 放在引号中将解决此问题。

这是我使用的工作测试。

    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

这也向您展示了如何测试不同的规则

注意** 通常我会得到用户的主文件夹:

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

但是在咆哮中似乎有一个错误,它返回一个咆哮文件夹

com.Growl.GrowlHelperApp/Rules.scpt:执行错误:cat:/Users/USERNAME/Library/Containers/com.Growl.GrowlHelperApp/Data/Dropbox/cb.txt:没有这样的文件或目录(1)

于 2013-08-18T11:09:05.183 回答