1

I use maid to run a few maintenance scripts regularly, via launchd. The time I chose for those tasks to run makes it very likely that I won’t suddenly decide to turn off my computer around then, but one can never be absolutely certain.

Sometimes, GUI apps prevent the computer from turning off due to unsaved changes. Can we replicate this via CLI? A bit like caffeinate but for power off instead of sleep.

1

How about actually using a GUI app to make an unsaved document?

osascript -e '
    tell application "TextEdit"
        activate
        set d to (make document)
        set text of d to "Your script is still running!"
    end tell
'
  • Too hacky and unreliable. Also hard to abort. – user137369 Feb 1 '18 at 21:59
  • Hard to abort? Can’t you just close TextEdit? – SilverWolf Feb 1 '18 at 22:45
  • Not programatically without closing the whole of TextEdit (which might contain legitimate documents). – user137369 Feb 2 '18 at 2:57
  • Oh, programmatically. Well...maybe there's some way to return the document from AppleScript and store it for later use. – SilverWolf Feb 3 '18 at 1:20
-1

the built in pmset utility can do this

sudo pmset autopoweroff 0
sudo pmset disksleep 0

Should work. If you want to see what all settings are available to pmset, and their currently set values:

pmset -g

You can also man pmset for more info on the pmset utility. Make sure to set the values back to their defaults after changing :)

  • Doesn’t work. I can still power off normally (even though the options did indeed change). – user137369 Nov 11 '15 at 15:23
  • What are you trying to do? Prevent a manual shutdown of the system? – Thought Space Designs Nov 11 '15 at 17:57
  • Yes. Like I said (emphasis added): “(…) suddenly decide to turn off my computer (…) GUI apps prevent the computer from turning off due to unsaved changes”. When do GUI apps typically do that other than when you’re trying to manually power off? If I only wanted to stop automatic power off, I’d use caffeinate, as mentioned. – user137369 Nov 12 '15 at 0:21
  • Good luck finding your answer. – Thought Space Designs Nov 12 '15 at 15:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .