Shutdown Mac OSX computer using python

Wolfgang Draxinger wdraxinger at darkstargames.de
Mon Dec 8 13:33:36 CET 2008


Håkan Hagenrud wrote:

> Hello, i'm a python noob!
> 
> But I would like to shutdown a 10.5.x mac computer using python
> (2.5.1)
> 
> this is my code:
> #!/usr/bin/python
> import SystemEvents
> down = SystemEvents.Power_Suite.Power_Suite_Events()
> down.shut_down()
> 
> the last call needs an additional argument, I cant find any
> documentation about this. Anybody knows?
> 
> Thank you!

Why so complicated? MacOS X is a Unix at it's base, so you can
use Unix commands.

#!/usr/bin/python
import os
os.system("shutdown -h now")

Must be run as root, won't work otherwise. You can however add to
sudoers (man visudo) shutdown as NOPASSWD program for the users
that want to execute the script and use "sudo shutdown ..."
instead of just "shutdown ..."

Wolfgang Draxinger
-- 
E-Mail address works, Jabber: hexarith at jabber.org, ICQ: 134682867




More information about the Python-list mailing list