Archive for October, 2009

cocoasudo: A graphical Cocoa based alternative to sudo

October 26th, 2009

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.

System Preferences app's use of Authorization Services API

System Preferences app's use of Authorization Services API

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.


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://

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.