Automatic MacOS shutdown

From time to time my Mac is doing stuff which takes quite awhile. Converting images, converting videofiles between formats or other stuff, which may take a long time (but reasonable predictable).

In those cases I run a little command in the terminal, to automatically shut down the Mac upon completion:

sudo shutdown -h +120

This command sets a timer which shutdown the machine after two hours (the 120 parameters being after 120 minutes).

#Cancelling shutdown

The command has no UI but sets a time. If you need to cancel the shutdown, simply write:

sudo killall shutdown

… and this will cancel the shutdown (if any is set). It does not tell if the shutdown timer was killed or not, but you can verify it by these commands:

sudo -i  
if ps -C shutdown > /dev/null; then echo "Shutdown is pending"; else echo "Shutdown is not scheduled"; fi

This command will tell you if a shutdown is pending or not. As these are unix commands they should also work on any linux server if needed.