applescriptlogoff

Prevent Dialog Box From Preventing User Log Out?


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?


Solution

  • 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.