Woxidu

It's too dangerous to go alone. Take this.

Archive for November, 2008


PyMacDialog

Download it

PyMacDialog is a small python script that reads a list of options from stdin, gives you a gui picker, and writes your selection to stdout. It serves a similar purpose to applications like dialog or CocoaDialog. The latter almost did exactly what I wanted except it only allows dropdown menus, not full lists (Using the NSTableView class).

After discovering PyObjC and seeing how easy it could be to write code that was both command-line friendly and Cocoa friendly, I decided to write PyMacDialog. The trickiest part was rooting through message boards and other open-sourced code to find out how to construct the UI purely within python without making use of any NIB files. I hope to put together some tutorials to illustrate the different parts.

If I have some command that generates some kind of list:

[eliman@dian-nao]-[scratch] $ ps auxww | grep -v grep |  grep Applications |\
awk '{print $11}' | awk -F'/' '{print $NF}'
iPulse
Terminal
Safari
Mail
Dropbox
iTunes
Twitterrific
iCal
Colloquy
Adium
HardwareGrowler
Caffeine
iTunesHelper
Vim

I can pipe this command through PyMacDialog.py and get this:

PyMacDialog

And then I can pick one, hit enter, and get this:

[eliman@dian-nao]-[scratch] $ ps auxww | grep -v grep |  grep Applications | \
awk '{print $11}' | awk -F'/' '{print $NF}' | ./PyMacDialog.py 
Dropbox
[eliman@dian-nao]-[scratch] $