如何在 OS X 中使用 osascript 或 AppleScript 显示模式窗口

Ser*_*gio 5 macos bash terminal applescript osascript

如何在 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'
Run Code Online (Sandbox Code Playgroud)

问题是它不是模态的。

如何解决以下问题?

Vic*_*Vic 1

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

\n\n
repeat while true\n    me activate\n    set userResp to display dialog \xc2\xac\n        "Yes or No?" as text buttons {"No", "Yes"} \xc2\xac\n        default button "Yes" with icon caution \xc2\xac\n        with title "Question" giving up after 5\nend repeat\n
Run Code Online (Sandbox Code Playgroud)\n\n

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

\n\n

希望有帮助。

\n