4

如何在 OS X 10.6.8 及更高版本中使用 osascript 或 AppleScript 显示模式(在所有应用程序、窗口中)窗口。

这是我做的一个脚本:

#!/bin/bash

osascript -e 'tell app "System Events" to display dialog "My Dialog" buttons {"OK"} default button 1 with title "My Dialog" with icon caution'

问题是它不是模态的。

如何解决以下问题?

4

2 回答 2

3

您可以使用“显示通知”命令将通知放在所有其他窗口上方(并放入通知中心),但您不能阻止用户使用他们的计算机。

display notification "Message"

另一种引起用户注意的方法是说点什么。

say "Message"
于 2014-08-07T05:03:33.557 回答
2

我最近写了一个脚本来监控我的 macbook 电池电量不足时。为了确保我没有错过警报,我执行了以下操作...

repeat while true
    me activate
    set userResp to display dialog ¬
        "Yes or No?" as text buttons {"No", "Yes"} ¬
        default button "Yes" with icon caution ¬
        with title "Question" giving up after 5
end repeat

即使我不小心单击了其他地方并且它被埋在另一个窗口下,代码也会继续重新显示消息。

希望有帮助。

于 2014-07-06T21:32:18.073 回答