Sudo is “a program for some Unix and Unix-like computer operating systems that allows users to run programs with the security privileges of another user (normally the superuser, a.k.a. root).” (Wikipedia reference). It works great for command line applications – especially for running them from a terminal prompt, or as part of a shell utility.
For Mac OS X Cocoa-based apps, there is analagous ability to sudo provided via the Authorization Services API. Use of the API allows you to prompt the user for their username and password requesting the ability to escalate privileges.
The Authorization Services API is a bit complicated. All the more so if you’re not writing a Cocoa app in Objective C. For example, maybe you’re using a scripting language, or you’re writing your GUI in Java / Swing for cross-platform use.
For that case, I’ve written a small utility that I’ve dubbed cocoasudo. Use cocoasudo in much the same way you’d use sudo. However, instead of users being prompted for their password in a Terminal window, they’ll get a dialog prompt via the Authorization Services API.
Usage:
cocoasudo [--icon=/path/to/icon.icns] ["--prompt=This prompt will be displayed to users."] command-to-launch [command-arguments...]
Both the –icon and –prompt parameters are optional and may be omitted.
Download the source on Github, or via your git client:
git clone git://github.com/performantdesign/cocoasudo.git
Or, if you don’t have Xcode, or don’t want to compile from source, you can download the cocoasudo binary directly here.
cocoasudo is Apache-licensed, so you can mostly use it as you see fit.