I have an OS X Python application that uses wxPython for it's GUI controls. I'm looking to prompt the user for administrative rights (akin to using the Authorization Service API in Objective-C) before starting a network service.
The closest library I have found is Bob Ippolito's Authorization library but it is fairly outdated and has compatibility issues with Snow Leopard (OS X 10.6.4 / Python 2.6.4).
My workaround would be to create an Objective-C launcher that runs the python application with administrative rights but that feels fairly kludgy.
Thanks for the help!
If it's just a shell command that you need to run, requesting elevated privileges, then you can do this:
os.system("""osascript -e 'do shell script "<commands go here>" " with administrator privileges'""")
It will run a shell command within the applescript interpreter and prompt the user for their account credentials; effectively running the command using sudo.
Note that you'll have fun escaping quotes within your command, e.g.
os.system("""osascript -e 'do shell script "mkdir -m 0775 -p \\"%s\\" " with administrator privileges'"""%d)
Hope that helps!
You could run your entire script with admin privileges by making it into a native Mac OS X application using Platypus.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With