How to display modal window using osascript or AppleScript in OS X

二次信任 提交于 2019-12-04 14:49:21

I wrote a script recently to monitor my macbook battery when it got low. To make sure I didn't miss the alert I did the following...

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

The code will keep redisplaying the message even if I accidentally click elsewhere and it gets buried under another window.

Hope that helps.

You can use the "display notification" command to place a notification above all other windows (and into Notification Center,) but you can’t block the user from using their computer.

display notification "Message"

Another way to get the user’s attention is to say something.

say "Message"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!