Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for a way to inject some more extensions into the OS X launch services database systematically so that when clicked, they execute in the terminal app just like .command files do by default.

Things like .ksh, .sh, and .csh would be nice to start, but I assume once I figure out how to add one, it's easy to do the rest.

An answer specific to Lion or Snow Leopard is fine, so a general-case answer for all OS versions is not necessary. It would be great if this were scriptable and wrote directly to the Launch Services database so I could automate this rather than going to finder on each mac and doing a lot of clicking.

share|improve this question
I'll probably have to dig into the dev docs to suss out what and how UTI are handled to do this properly.… – bmike Aug 5 '11 at 16:52
Searching for RCDefaultApp led me to this answer… but somewhere else recently I saw RCDefaultApp mentioned not far from Magic Launch … got it: probably not as useful as the first link, – Graham Perrin Aug 5 '11 at 17:01
In a linked question, a comment draws attention to duti. Should that be an answer here? Or for this question, will you prefer to work only with what's integral to OS X? – Graham Perrin May 17 '12 at 7:12
up vote 3 down vote accepted

If a file is opened with Terminal, and has the execute bit set, then Terminal will execute it.

Get Info on a .sh file and set it to be opened with Terminal, and click the Change All button.

share|improve this answer
When I made the .sh file executable, another app claimed it on my mac. Going to finder, get info, right click, ignore the warning that Terminal might not be able to open .sh does work. Technically, this is certainly doable - but I'll leave the answer open for something that directly writes into the Launch Services database programmatically instead of through the UI. – bmike Aug 5 '11 at 16:50

To prefer Terminal to open .sh files — using the defaults command, without using Finder

In most cases, all that's required should be possible from the command line …


Two commands:

defaults read | grep -B 1 -A 3

defaults read | grep -B 1 -A 4 "LSHandlerContentTag = sh;"

If either command reveals an existing preference

Use Xcode or any other suitable property list editor to remove the relevant dictionary from the LSHandlers key within the following file:



Adding to LaunchServices preferences, for Terminal to view and edit .sh files

Two one-line commands.

Depending on your requirements, the first command alone may suffice:

defaults write LSHandlers -array-add '{ LSHandlerContentType = ""; LSHandlerRoleViewer = ""; LSHandlerRoleEditor = ""; }'

defaults write LSHandlers -array-add '{ LSHandlerContentTag = "sh"; LSHandlerContentTagClass = "public.filename-extension"; LSHandlerRoleViewer = ""; LSHandlerRoleEditor = ""; }'

For the new preferences to be respected

Modifications to the user domain persistence layer of Launch Services must be acknowledged. For this, least disruptive to the end user will be:

  • a restart of the operating system.

From the command line, if immediate restart is acceptable:

sudo shutdown -r now


Understanding support for .sh (

Consider the result of the following command:

defaults read /Applications/Utilities/

Terminal aside for a moment: it's sometimes inappropriate (or simply worthless) to force opening of a document type, by an app that is designed without support for that type.

For Terminal, I imagine no harm in handling the type.

share|improve this answer
Discuss – Graham Perrin Apr 29 '12 at 12:36
@Lri in two or more tests, Terminal worked as expected for with a simple !sh one-liner — after the run of lsregister completed. But (as you note under the other question) using lsregister in that way is not without annoyance. I'll post something to Ask Different Chat for your attention. – Graham Perrin Apr 30 '12 at 13:37
I was really hoping @Lri had words of wisdom. I asked for detail and Graham - you are prolific on detail. I'm not able to put your answer to practical use (yet perhaps) but I very much appreciate the extra eyeballs and suggestions so far on this. – bmike May 4 '12 at 19:16
Thanks! — expect the grey area of this answer to be tidied in due course. – Graham Perrin May 4 '12 at 20:02

The Unix way of doing this is to open and setting the scripts to executable with chmod +x

Or you can make a link from /bin/bash to /Applications and define /Applications/bash to be the default application for .sh files in the Get Info dialog. But this seems to be kind of wierd IMHO.

share|improve this answer
The executable files are claimed by another app. I'm guessing I'll need to massage the database directly and monitor it if other apps as for this UTI -… – bmike Aug 5 '11 at 16:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.