Tuesday, July 7, 2015

Mac OS X "Open"

I just love the OS X command 'open'.  No matter where you are you can just type open filename and it'll figure out the associated app and open the file with it.  I wished there was a Linux equivalent 'till go figure... there is one.

I found this stackoverflow post mentioning the command xdg-open.

that's a bit convoluted to write, so i made an alias

alias lopen='xdg-open'

lopen foobar.pdf
lopen .
lopen somefile.py

All of it works flawlessly.  :D I love it

PS. open command is taken by an openvt binary.  Hence lopen.

Hint:  To change the default association, in gnome at least:

Right-click->Properties->Open With->Set as default (lower right).

If you need to add a custom application. (I'll assume you created a .desktop icon and it shows up properly in your gnome menu using alacarte or by hand)

You need to update your:

 ~/.config/mimeapps.list

For example in my case, I added the following line:

text/plain=alacarte-made.desktop;

where alacarte-made.desktop is my sublime editor.

You can fine a list of most of the supported mimetypes in:

/usr/share/applications/defaults.list