Skip to content

Instantly share code, notes, and snippets.

@bruienne
Last active July 26, 2023 21:58
Show Gist options
  • Save bruienne/0cce2d93687985c8df14 to your computer and use it in GitHub Desktop.
Save bruienne/0cce2d93687985c8df14 to your computer and use it in GitHub Desktop.
logout watcher
onLogout() {
# Insert whatever script you need to run at logout
exit
}
echo "INFO - Watching ${HOME}" >> /var/log/org.my.log
trap 'onLogout' SIGINT SIGHUP SIGTERM
while true; do
sleep 86400 &
wait $!
done
@mbattou
Copy link

mbattou commented Jan 28, 2016

Hi there,

I have a quick question, I have set up a logout script and its plist to be triggered at logout with Launchd. However, the logout script does not start at logout or restart/shutdown. Its only triggered by executing the scripts it self and killing it with ctl+c or by laucnctl load/unload.

I am working on Yosemite 10.10.5, do I need to upgrade to get the logout script to work. I do not want to use logout hooks as they're deprecated.

How did you go about that?

@alpeyev
Copy link

alpeyev commented Sep 20, 2017

I have an exact same issue. Did you find a solution mbattou?

@geoffrepoli
Copy link

@alpeyev might be a change in how macOS handles orphaned processes, probably a SIGINT to the trapped function. A workaround could be something like setting up a WatchPaths launch daemon, and using the onLogout() script to touch a tmp file.

@Maximetinu
Copy link

This doesn't work with AppleScripts. If I try to run an apple script at line 2 I get 73:107: execution error: An error of type -10810 has occurred. (-10810)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment