1

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
2
  • Can you please clarify what you need here? Are you looking for a notice the user needs to see before they logout? Is it informational only or do the need to confirm it/press a button? Or is it a notice which is displayed after the logout is completed (so it is visible to whoever looks at the screen after the logout)?
    – nohillside
    Jul 11, 2018 at 12:58
  • @nohillside If before this may be helpful: apple.stackexchange.com/questions/74956/… Jul 11, 2018 at 13:03

1 Answer 1

1

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:

  1. Create a plain text (.txt) or rich text (.rtf) document named PolicyBanner that contains your banner.
  2. 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:

enter image description here

enter image description here

5
  • 1
    Hopefully as soon as refers to after logout. Jul 11, 2018 at 12:06
  • Good answer, learnt something new here. But I'm not sure the answer matches the problem the OP has :-)
    – nohillside
    Jul 11, 2018 at 12:59
  • @nohillside Well since there was not much detail here I went with the technicals of what they were saying. "As soon as user logs off" is referring to the time post logout has completed therefore this should be adequate. But I do see how with more details this may be not the correct answer :) Jul 11, 2018 at 13:01
  • I need a text window when the user has logout! Not Login!
    – steffus
    Jul 12, 2018 at 7:30
  • @steffus It works either way. Jul 12, 2018 at 10:40

Not the answer you're looking for? Browse other questions tagged .