动作按钮 applescript 函数

Action buttons applescript functions

我正在尝试制作一个 AppleScript,它会在我收到特定电子邮件时创建通知。

规则已设置,我有一个脚本可以使用以下代码启动应用程序:

display notification "A newBuild is now available!" with title "New Build"
tell application "Safari"
    activate
    tell window 1
        set current tab to (make new tab with properties URL:"https://latestSuccessful")
    end tell
    tell application "System Events"
        set visible of process "Safari" to true
    end tell
end tell

这会启动 Safari,并在显示通知后立即转到网页。

理想情况下,我会将通知显示为警报,并在 'Show' 按钮上执行操作,然后将我带到网页。 'Close button' 自然关闭警报。

这可能吗?在此先感谢您的指点。

在 AppleScript 中无法使用带有操作按钮的通知,
因为 AppleScript 无法处理回调。

你绝对可以做到!为此,您必须安装 Growl。它曾经是免费的,但现在收费 4 美元。在我看来,这是一个非常好的长期投资,它可以让你用 AppleScript 中的通知做一些很棒的事情。安装后使用的代码是这样的:

set notifications to {"EMailNotify"}
tell application "Growl"
    register as application "AppleScript App" all notifications notifications default notifications notifications
    notify with name "EMailNotify" title "E-Mail received!" description "it's here!" application name "AppleScript App" callback URL "http://www.apple.com/"
end tell

请记住,您必须使用第一行列表中的一个通知名称作为第四行通知的名称,并且您必须使用与注册应用程序相同的应用程序名称在第三行,作为第四行的 "application name"。 Growl 允许您将回调 URL 指定为参数,这应该让您准确地找到您正在寻找的东西!

请记住,您可以将 Growl 配置为使用 OS X 通知,以便准确获得您正在寻找的内容,但 Growl 的通知可定制性更高。

你的意思是这样的吗?

set alertReply to display alert "New Build" message "A new build is now available!" buttons ["Cancel", "Show"] default button 2 giving up after 5
if button returned of alertReply is equal to "Show" then
    tell application "Safari"
        activate
        tell window 1
            set current tab to make new tab with properties {URL:"http://www.google.com"}
        end tell
    end tell
end if