How to set the default application for certain file types on Mac OS X?

On Mac OSX lion, I am trying to set the default application for certain file types. Using the apple script below, 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 install the same default application for all files that have a file type or extension like "abc".

I tried the following to do this. He added an entry to <HOME>/Library/Preferences/com.apple.LaunchServices.plist . But the files do not open 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 someone knows what I am missing to achieve this.


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 
+6
source share
3 answers

You may not be doing anything wrong, but the com.apple.launchservices file needs to be reloaded. You can log out, wait a few minutes, or force startup services to restart. In the following example, I say that public.comma-separated-values-values-text files (note: this does not mean that every CSV file is this type of content) should be opened using 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" 
+5
source

I'm not sure that you are only trying to do this programmatically. You?

Otherwise:

In the file, select "get information", and in the "open with" section, select the application name. Click the Change All button

0
source

You might want to take a look at RCDefaultApp and its source code. This is a program that allows you to set what types of files open, with which applications in Launch Services.

0
source

Source: https://habr.com/ru/post/907821/


All Articles