When logging into a Mac remotely, sometimes it's necessary to restart the computer (for example, after performing an update using
softwareupdate). Although one could use
sudo reboot, this doesn't allow the Aqua apps to exit gracefully. So if there are any unsaved changes in an open document, you will lose those changes. Instead one should use AppleScript:
% sudo osascript -e 'tell application "Finder" to restart'
Notes:
- If your user isn't the currently logged in user, you might get some errors in the command line, but it will work.
- sudo might not be required.
- If there is an open application with unsaved changes, the restart will time out. This is the intended behaviour. You could try to use applescript to save and exit that application (if said application is scriptable).
[
robg adds: If the remote machine absolutely positively must be restarted, and you don't want to lose any unsaved changes (and the apps aren't scriptable), you'll have to use something like Timbuktu or OSXvnc to connect to the GUI on the remote Mac. Once you've taken that effort, though, you might as well just choose Restart in the GUI as well!]