ben
ben

Reputation: 113

Prevent/inhibit macOS from shutting down while a shell script is running

Is there a way to prevent shutdown on macOS while a particular bash script is running without changing the actual shutdown command?

This question has some linux based solutions that would probably work by aliasing the shutdown command, but I am just wary of doing it this way. Call it a lack of knowledge combined with a desire to not alter more than I need to.

This question asks essentially what I am asking but the accepted (and only) answer pertains only to sleep.

Ideally a solution will provide some way to prevent shutdown from within the bash script that is running. If this is not possible, the answer that requires the fewest changes elsewhere will be the best one.

Upvotes: 0

Views: 389

Answers (1)

accdias
accdias

Reputation: 5372

The command you probably are looking for is this:

sudo systemsetup -setcomputersleep Never

And since we are on this topic, you can get the actual state using this command:

sudo systemsetup -getcomputersleep

I hope those help you.

EDIT: I just found this excellent and more complete article: How to customise the power settings from Terminal on the Mac.

Upvotes: 2

Related Questions