I have a headless system that is controlled remotely that I need to shutdown/restart in an automated way (without the use of VNC or local keyboard/mouse).
Using various commands via SSH or via my daemon work as expected and restart the machine:
sudo shutdown -r now or
osascript -e 'tell application "System Events" to restart'
However these commands cause the OS to reopen windows of any running applications even though the following are all true:
- When logging out normally
Reopen windows when logging back inis unchecked
- Only the item I want to start with the login is listed in
System Preferences > Users & Groups > Login Items.
defaults write -g ApplePersistence -bool nois set
System Preferences > General > Ask to keep changes when closing documentsis checked or unchecked
System Preferences > General > Close windows when quitting an appis checked or unchecked
Recent Itemsis set to any value (has no effect)
TALLogoutSavesSateset to NO
In my case I can't actually use the applescript since 10.7+(?) warns when another machine is network shared with AFP or SMBed causing the shutdown to fail. The
shutdown command forces the restart without popping up a dialog which is exactly what I need. However when the machine starts up I want exactly one application to start at login, and it is listed in Login items.
The machine is set to automatically log in so this application can run but if any other windows were open (Terminal or TextEdit with unsaved changes) want my shutdown/restart script to force close any open applications without saving and NOT open on next login. I also would rather not for-loop through all the user processes sending each a
SIGKILL manually before sending the
I am fully aware this may cause data loss (if the user did not save their document) but this this is typically an unattended machine that I want a restart to take the machine to a known state, not the state it was left in.
AFAICT none of these work to cleanly shutdown/restart the machine in 3.7+.