GUI Admin Tip for Mac OS X Python

I have an OS X Python application that uses wxPython for its GUI controls. I want to offer the user administrator rights (similar to using the authorization service API in Objective-C) before starting the network service.

The closest library I found is the Bob Ippolito Authorization Library , but it is quite 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 launches a python application with administrator privileges, but this is pretty annoying.

Thanks for the help!

+4
source share
3 answers

You can run the entire script as administrator by entering it into a Mac OS X application using Platypus .

+2
source

If this is just a shell command that needs to be run requesting elevated privileges, you can do this:

os.system("""osascript -e 'do shell script "<commands go here>" " with administrator privileges'""") 

It will run a shell command in the applescript interpreter and ask the user for its credentials; effectively running the command with sudo.

Please note that it will be fun to reset quotes in your command, for example

 os.system("""osascript -e 'do shell script "mkdir -m 0775 -p \\"%s\\" " with administrator privileges'"""%d) 

Hope this helps!

+5
source

You might want to check out the answer to another question mentioned here: What API should I use to increase user privileges for superuser on Mac OS X?

+1
source

All Articles