2

In my Python GUI application, I have to run a command as root to perform a certain action (to be specific, it installs a Python module system-wide). On Linux I simply use gksudo or kdesu prefixed to the command passed to subprocess.Popen(). There doesn't seem to be a Mac equivalent, unfortunately. I have seen this question before pointing to some complicated Objective-C code called BetterAuthorizationSample... I don't really understand it and would prefer to not write Objective-C code to do this simple task. If there's a simpler way, I'd like to know. I'm thinking I could make my own password dialog box and pass it to regular command-line sudo on stdin.

Luke McCarthy
  • 749
  • 1
  • 7
  • 20
  • N.B. `sudo` might not simply use stdin. Have a read of this: http://www.noah.org/wiki/Pexpect#Q:_Why_not_just_use_a_pipe_.28popen.28.29.29.3F – Thomas K Oct 10 '11 at 16:29

2 Answers2

1

I don't know off the top of my head how to elevate your privileges, but you could use a bit of AppleScript to ask for a password. For an example, see https://github.com/apenwarr/sshuttle/blob/master/ui-macos/askpass.py

David Wolever
  • 139,281
  • 83
  • 327
  • 490
0

I have not found an optimal solution, but I just posted my currently working solution here

It uses osascript to relaunch itself with root permissions.

Community
  • 1
  • 1
faern
  • 63
  • 6