【问题标题】:Action buttons applescript functions动作按钮小程序函数
【发布时间】:2016-02-21 20:12:04
【问题描述】:

我正在尝试制作一个 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 并在显示通知后立即进入网页。

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

这可能吗?提前感谢您的任何指点。

【问题讨论】:

    标签: notifications applescript


    【解决方案1】:

    你的意思是这样的吗?

    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
    

    【讨论】:

    • 他想要通知,而不是警报。 “警报样式”是 OS X 支持的一种通知样式,尽管它与“显示警报”的作用不同,甚至关闭。咆哮是最好的选择。
    • 理想情况下我想要一个通知,但这也适用于我。非常感谢这里的帮助。我玩这个小脚本玩得很开心。 (在这方面我是菜鸟)
    【解决方案2】:

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

    【讨论】:

    • 这很不幸。有没有办法绕过它?我已经将脚本打包在一个小程序中,有什么方法可以从那里完成吗?
    • 不使用纯 AppleScript 小程序,您需要 AppleScriptObjC 或 Cocoa 应用程序
    • 很有可能,看看我的回答。
    • 当然可以使用第三方解决方案,问题是关于display notification
    • @vadian 不。他想在收到邮件时用 AppleScript 显示一个通知,并允许它打开一个 URL,并以“显示通知”为例。不过,这不是他要问的。
    【解决方案3】:

    你绝对可以做到!您必须为此安装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
    

    请记住,您必须使用第一行列表中的一个通知名称作为第四行通知的名称,并且您必须使用与您在第三行,作为第四行的“应用程序名称”。 Growl 允许您将回调 URL 指定为参数,这应该会为您提供所需的内容!

    请记住,您可以将 Growl 配置为使用 OS X 通知来准确获取您要查找的内容,但 Growl 的通知更可定制。

    【讨论】:

    • osx 中几乎所有不错的资源都不是免费的,puag。
    • 我是 osx 用户,但是 osx 中有很多不错的开发者工具不是免费的,但没关系……这是苹果的世界。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-20
    • 2017-01-30
    • 1970-01-01
    • 1970-01-01
    • 2012-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多