5

How to display modal(over all apps, windows) window using osascript or AppleScript in OS X 10.6.8 and later.

Here a script I do:

#!/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'

The problem is that it's not modal.

How to fix the following issue?

Serge
  • 2,031
  • 3
  • 33
  • 56
  • 2
    I'm not certain, but I think there are no **system**-modal windows on OSX, i.e., there is no way to block **all** applications. If your command is run from a Terminal window, the dialog will block the calling shell, though. – mklement0 Jan 29 '14 at 15:01

2 Answers2

3

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"
Simon White
  • 686
  • 5
  • 9
1

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.

Dude named Ben
  • 507
  • 3
  • 16
  • 1
    The code as written never terminates. It needs to check the result of userResp and exit on the non-gave up case. – studgeek Nov 14 '19 at 22:36
  • I discovered this the hard way by just throwing this in and testing it without reading the above comment first. Not disastrous or anything, but annoying and had to Force Quit Automator to get out of it. Someone should provide an edit which fixes this. – JVC Jun 03 '20 at 14:12