使用咆哮2.1规则运行Applescript

使用咆哮2.1规则运行Applescript,applescript,dropbox,growl,Applescript,Dropbox,Growl,目前,我有一个流设置,结果是一个文件--“cb.txt”--被添加到我的Dropbox中。我收到一个带有应用程序名“Dropbox”和便笺标题“cb.txt added”的咆哮通知。我希望“cb.txt added”通知运行applescript,将文本从cb.txt复制到我的剪贴板。可以找到咆哮通知的规则 下面是我想要运行的applescript(当我通过applescript自行运行它时,它成功地将cb.txt的内容添加到剪贴板): 我已将此文件作为apple脚本保存到~/Library/A

目前,我有一个流设置,结果是一个文件--“cb.txt”--被添加到我的Dropbox中。我收到一个带有应用程序名“Dropbox”和便笺标题“cb.txt added”的咆哮通知。我希望“cb.txt added”通知运行applescript,将文本从cb.txt复制到我的剪贴板。可以找到咆哮通知的规则

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

我已将此文件作为apple脚本保存到
~/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

显然,我有点困了。如果有人能给我建议,当我收到一个特定的咆哮通知时,如何让我的工作applescript代码运行,我将不胜感激

可以使用app name,但如果不在字符串周围加引号,则会将其视为变量

如果在尝试访问/使用变量之前未声明该变量,则会出现错误

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

2013年8月18日11:46:11.961咆哮[89225]:完成错误:错误 Domain=NSPOSIXErrorDomain Code=2“无法执行该操作 已完成……/图书馆/申请 Scripts/com.Growl.GrowlHelperApp/Rules.scpt:execution error: 未定义变量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 
但咆哮中似乎有一个bug返回咆哮文件夹

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


我在那个教程页面上没有看到他们提到应用程序名称的地方,你有没有尝试过不使用if语句?还有,你有没有尝试过在引号中加上“Dropbox”?嗨@josh,咆哮页面没有更好地显示这一点并不奇怪。我有时发现他们的页面缺少细节。因为你使用的是应用程序“咆哮”中的术语“您可以使用咆哮sdef的任何属性,只要它们以正确的方式使用。如果你不能使用app name,那么就很难评估多个规则。非常感谢@markhunte,这就成功了。我需要做一些测试,以确定Growl文件夹中的许多脚本中需要保留哪些脚本,但它现在工作得很好。我在iPhone上复制文本,在中运行“粘贴”脚本,然后文本就可以在我的OSX剪贴板上使用。很好@Terrymcall建议进行编辑,这意味着返回咆哮文件夹而不是用户主文件夹的错误是由于沙箱造成的<代码>由于咆哮现在是沙盒,它返回咆哮文件夹。也许是这样。但我把它归类为bug,而不是预期的行为。将脚本放在
com.Growl.GrowlHelperApp
文件夹中意味着用户同意脚本正常运行并与用户环境交互。我不能说这是苹果的错还是咆哮。
set homePath to (path to home folder from user domain) as text