Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 574
Mathan Kumar Avatar asked Feb 07 '12 07:02

Mathan Kumar


2 Answers

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"
like image 55
dj bazzie wazzie Avatar answered Oct 05 '22 22:10

dj bazzie wazzie


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"

like image 37
xcoder Avatar answered Oct 06 '22 00:10

xcoder