Show Dialog Window if User logout on High Sierra When a user logout, I want to display a window. In this window should be a text (Please save your data...). After the user has pressed OK. The process logout continue. Is this possible?


onLogout() (
    # that works:
    if [ "$USER" != "admin" ] && [ "$USER" != "Administrator" ]; then
        rm -Rf ~/Downloads/*
        rm -Rf ~/Movies/*
        rm -Rf ~/Music/*
        rm -Rf ~/Pictures/*
        rm -Rf ~/Public/*
        rm -Rf ~/Desktop/*
    fi
    # it doesn`t work:
    res=$(osascript -e 'tell app "System Events" to display dialog "Please save yout Data!" buttons {"Cancel", "OK"} default button 1 with icon caution with title "Important Information!"' 2>/dev/null)

        if [[ $res == *OK* ]]; then 
            # continue logout?
        else
            # break logout?
        fi
    exit
)
trap 'onLogout' SIGINT SIGHUP SIGTERM
while true; do
    sleep 86400 &
    wait $!
done
Yes this is possible.

You can use the "User Policy Banner" feature.

Although used mainly in cafes and other public places to make user agree to a ToC this feature can be used to create a dialog box.

From the related Apple support article:

A policy banner is a banner that you can display at the login window that requires a user to acknowledge it before proceeding.


  Create a banner
  
  You can set a login message that appears at the login screen of your
  Mac. You can also set a "policy" banner to display a longer message
  that you must accept before you can log in. This can be useful in
  situations where you need users to agree to or acknowledge terms or
  conditions before using the computer, such as an Acceptable Use
  Policy.
  
  Use these steps to create a policy banner:
  
  
  Create a plain text (.txt) or rich text (.rtf) document named PolicyBanner that contains your banner.
  Copy the PolicyBanner file to the /Library/Security/ folder. 
  
  
  The next time you restart the computer, the banner you created appears
  when you would normally see the login screen.


The banner will look like this: