How to run a script before shutting down MacOS
1. The file can contain something like :
#!/bin/bash
say 'Hasta la vista baby!'
2. Then give exuction rights :
sudo chmod +x /Users/Shared/logoutHook.sh
3. Finally hook the script to the logout procedure :
sudo defaults write com.apple.loginwindow LogoutHook /Users/Shared/logoutHook.sh