0

I want to shut down my computer(mac) using a python script for some code I have written. I have tried the following

os.system('shutdown -s')
os.system('shutdown -h now')

But both of these produce the output 256 and my system doesn't shut down.

I read it might be due to not having root privileges but I guess I can't provide root privileges through python. Is there a way I can run a python script and shut down my mac with the above problem ?

1 Answers1

1

For restart:

re_start = ["shutdown", "-f", "-r", "-t", "30"]

For shutdown:

 shut_down = ["shutdown", "-f", "-s", "-t", "30"]

Hence:

def shutdown(self):
    import subprocess
    subprocess.call(shut_down)
DirtyBit
  • 16,613
  • 4
  • 34
  • 55