Pregunta

We have a simple .app made with applescript editor that pops up a display dialog box when a user logs in. The problem is that many users ignore the box and don't press "ok" to close it. If it's left open it will prevent the user from logging off the computer.

Is there any way to prevent the dialog box from holding up the log off process?

¿Fue útil?

Solución

2 things I can think of: 1) you can put a "giving up after" command on the dialog box so that it's automatically dismissed after a time, for example 5 seconds...

display dialog "Hello" giving up after 5

Or you can write yourself a logout script. This script will be run when a user logs out. Something like this would work.

tell application "System Events"
    if exists process "ApplicationName" then
        set itExists to true
    else
        set itExists to false
    end if
end tell

if itExists then
    tell application "ApplicationName" to activate
    tell application "System Events" to keystroke return
end if

Google for "logout hook" to find how to run a script at logout.

Otros consejos

May I rather ask, why you don't just modify the AppleScript code to close the dialog box automatically after, let's say, 5 minutes? This will be definitely easier than "hacking" a hard log-off into the system.

display dialog "Hello World" buttons "Ok" giving up after (5 * 60)

This dialog will auto-close after 5 minutes for example. Long enough for users to read it, if they really care about it and the other ones ignore it anyway, as you pointed out in your question.

Unfortunately, display dialog always requires action from the user to go away, unless you have the notification go away on its own using “giving up after”, without them necessarily reading it.

Assuming you need them to read it, and if you have control over the computers it’s going to be on, you could use Growl to display your notifications.

It occurs to me you could put the display dialog in an idle handler, and if they actually click “ok” have the script quit; if they don’t click “ok”, use “giving up after” as described in the other answers to make it go away after however many seconds you want and then pop it back up again on the next idle. This could be extremely annoying, and still runs the risk of blocking logout if they happen to log out while the dialog is up.

on idle
    --display the alert for 7 seconds
    display alert "Very Important Message" giving up after 7
    if the button returned of the result is "ok" then
        quit
    end if

    --idle for 90 seconds
    return 90
end idle

This work for me, force user logout. Disable “Reopen Windows When Logging Back In” in Mac OS X Completely and Logout confirmation

tell application "System Events"
    keystroke "Q" using {command down, option down, shift down}
    quit
end tell
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top