It seems that Apple isn't interested in a logout hook replacement, as they closed my issue inquiring about one.
However, one of the improvements in Yosemite is that launchd now properly sends signals down to shell scripts. What this means is that you can now do a log-out task like so:
Here's an example logout.sh:
echo 'Logging out' >> ~/Logs/logout.sh.log
trap 'onLogout' SIGINT SIGHUP SIGTERM
while true; do
sleep 86400 &
This will simply sleep (asynchronously, doing it synchronously without the ampersand doesn't seem to work) until it receives one of the trapped signals, at which point it will execute the
All you need to do is launch that script using a
RunAtLoad launch agent or launch daemon and it will run at log-out or shutdown, though it's important to bear in mind that tasks only have a limited amount of time to complete before they are killed instead, so this shouldn't be used to run anything that takes a long time, or requires a network connection that could be delayed etc.
Of course this is of no use to anyone on Mavericks or earlier, but under Yosemite this now seems to work as expected; so I was actually doing it right in the first place,
launchd just wasn't sending the signals properly :)
NOTE: For this to work the shell scripts seems to need to be executed directly by launched, i.e - it shouldn't invoked via
sh. So if it were placed in
~/Library/Scripts/foo.sh your program arguments might look like: