Perform zsh / spotlight / application completion

Nov 23, '05 05:58:00AM

Contributed by: bpm

I was recently inspired to realize my goal of intelligent completion of the open(1) command using the built-in zsh facilities (man zshcompctl) and Spotlight. It is believed that the command...

 compctl -f -x 'c[-1,-a]' -M 'b:=*' -k _apps -- open
...provides this. I believe what it does is: This means that without -a, filenames and directories are completed, and that after the application has been completed, then filenames and directories will be completed; therefore an argument can be supplied to the application.

To populate the _apps array, I use these commands:

$ typeset -a _apps
$ _apps=(${(f)"$(mdfind "kMDItemKind == 'Application'")"})
An example run is below.

[bpm@snafu] c:~>typeset -a _apps
[bpm@snafu] c:~>_apps=(${(f)"$(mdfind "kMDItemKind == 'Application'")"})
[bpm@snafu] c:~>echo ${#_apps}
398
[bpm@snafu] c:~>echo ${_apps[0]}
/Applications/iPhoto.app
[bpm@snafu] c:~>compctl -f -x 'c[-1,-a]' -M 'b:=*' -k _apps -- open
[bpm@snafu] c:~>open -a /Library/Application Support/Adobe/Workflow/Adobe Workgroup Helper
[bpm@snafu] c:~>open -a Photo
/Applications/Adobe Photoshop Elements 2/Photoshop Elements 2.0
/Applications/Hewlett-Packard/HP Photo and Imaging Software/HP E-mail Portal/HP E-mail Portal
...
/Applications/Hewlett-Packard/HP Photo and Imaging Software/HP Tools/HP Image Dropper.app
/Applications/iPhoto.app
/Library/Documentation/Applications/iPhoto/iPhoto Getting Started.app
[robg adds: This worked as described when I tested it using the zsh shell...]

Comments (6)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2005111609002539