Path handler in MacOSX terminal
In the terminal we often see URLs or file paths. We mark them and copy‑and‑paste them into our tools of choice. You probably already knew, that you can open URLs directly in the browser via CMD + Click, but you can also do with file paths. Sadly almost all files are then opened with Xcode. Wouldn’t it be nice to change that? We can.
Open Ruby files with RubyMine
Let’s play it through with a concrete example. After checking the git status
we would like to have a closer look at the affected file in RubyMine.
First open the LSHandlers with Xcode:
open -a Xcode ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist
Use the + sign to enter a new array entry of the type Dictionary with the keys: LSHandlerRoleAll, LSHandlerContentTagClass, LSHandlerContentTag. It should look like this in the end:
If you wonder how to find out the bundle identifier of RubyMine (“com.jetbrains.rubymine”), this is one of many ways:
/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier' /Applications/RubyMine.app/Contents/Info.plist
After rebooting your machine you should be able to CMD + Click on paths with *.rb filename extensions in your terminal and open the respective file in RubyMine.
More path types
Sadly I didn’t find any documentation about the possible key/value pairs in LSHandlers. But I was able to come up with the following valid combinations for URLs and content types:
- LSHandlerURLScheme (e.g. “ftp”) and LSHandlerRoleAll
- LSHandlerContentType (e.g. “public.shell-script”)and LSHandlerRoleAll
There are non-default tools which can do more and with comfort, like for example duti, RCDefaultApp or this guy’s Ruby script.
If someone has access to thorough documentation about LSHandlers, I’d be glad to reference it.