Mathan Kumar
Mathan Kumar

Reputation: 684

How to set default application for specific file types in Mac OS X?

In Mac OSX lion, I'm trying to set default application for specific file types. Using the below apple script, we can set the default application for the specific "file.abc".

tell application "System Events"
set default application of file "/Users/test/Desktop/file.abc" to "/Applications/TextEdit.app"
end tell

But I want to set the same application as default for all the files having the filetype or extension as "abc".

I have tried the following to get it done. It added an entry in <HOME>/Library/Preferences/com.apple.LaunchServices.plist. But the files are not opened with the specified application.

defaults write com.apple.LaunchServices LSHandlers -array-add "<dict><key>LSHandlerContentTag</key><string>abc</string><key>LSHandlerContentTagClass</key><string>public.abc</string><key>LSHandlerRoleAll</key><string>com.apple.textedit</string></dict>"

Hope somebody knows what i m missing to achieve it.


Answer Found :

defaults write com.apple.LaunchServices LSHandlers -array-add "<dict><key>LSHandlerContentTag</key><string>ugurugu</string><key>LSHandlerContentTagClass</key><string>public.filename-extension</string><key>LSHandlerRoleAll</key<string>org.videolan.vlc</string></dict>"
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain system -domain user

Upvotes: 13

Views: 9813

Answers (3)

svth
svth

Reputation: 1310

You might want to take a look at RCDefaultApp and its source code. It's a program that lets you set which file types are opened by which apps in Launch Services.

Upvotes: 0

dj bazzie wazzie
dj bazzie wazzie

Reputation: 3542

Maybe you're doing nothing wrong but that the com.apple.launchservices file just needs to be reloaded. You can logout, wait a few minutes or force launchservices to restart. In the following example I say that public.comma-separated-values-text files (note:This doesn't mean that every CSV file is this content-type) must be opened with TextEdit instead of Excel.

do shell script "defaults write com.apple.LaunchServices LSHandlers -array-add '{ LSHandlerContentType = \"public.comma-separated-values-text\"; LSHandlerRoleAll = \"com.apple.TextEdit\"; }'"

do shell script "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain system -domain user"

Upvotes: 7

xcoder
xcoder

Reputation: 967

I'm not sure if you're only trying to do this programmatically. Are you?

Otherwise:

On the file, choose "get info", and under "open with" select the name of the application. Click on the button "Change All"

Upvotes: 4

Related Questions