Macos – Access Finder’s “Open With” menu from the commandline (for tab completion)

bashcommand linemacostab completionzsh

On Mac OS X, I know one can open a file from the commandline with its default application with open, and with other applications with open -a <application name>. Thus,

open movie.avi
open -a VLC movie.avi
open movie.avi -a VLC

all work. My only complaint is that when I type

open movie.avi -a <TAB>

it completes over all applications that exist on the computer — for instance in zsh I get

zsh: do you wish to see all 793 possibilities (200 lines)? 

— while what I would like is for it to complete over only the handful of applications that Finder's "Open With" menu would have shown.

So is there a way to access this list that Finder knows, and make my shell (zsh, but I can switch to bash if it helps) aware of the list, in such a way that tab completion would show only those applications?

Best Answer

AllApplications

$ AllApplications -h

Created 03 March 2011 by Hank McShane
version 0.1
requires Mac OS X 10.4 or higher

Use this command line tool to get the path to all applications that can open a file from Launch Services.

Usage: AllApplications -path path/to/file

$ ext=png; f=/tmp/allapps.$ext; touch $f; AllApplications -path $f; rm $f
/Applications/Preview.app
/2/copies/Safari.app
/Applications/TeX/LaTeXiT.app
/Applications/WebKit.app
/Applications/Sequential.app
/Applications/ImageOptim.app
/Applications/Acorn.app
/Developer/Applications/Graphics Tools/Core Image Fun House.app
/2/copies/Preview.app
/Developer/Applications/Dashcode.app
/Applications/GraphicConverter.app
/Applications/Google Chrome.app
/Applications/Adobe Photoshop CS5/Adobe Photoshop CS5.app
/Applications/Utilities/QuickTime Player 7.app
/Applications/Utilities/ColorSync Utility.app
/Applications/Safari.app
/Applications/Adobe Device Central CS5/Adobe Device Central CS5.app
/Applications/Firefox.app

duti

$ duti -d public.png
com.apple.Preview
$ duti -l public.png
com.SequentialX.Sequential
com.flyingmeat.Acorn
net.pornel.ImageOptim
com.apple.system-library
com.apple.ColorSyncUtility
com.apple.Preview

(It's missing some apps that are displayed in the open with menu though.)

Related Question