如何在Mac OS X中为特定文件类型设置默认应用程序?

时间:2020-12-04 00:21:53

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".

在Mac OSX Lion中,我正在尝试为特定文件类型设置默认应用程序。使用下面的Apple脚本,我们可以为特定的“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".

但我想为所有文件类型或扩展名为“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.

我已经尝试了以下方法来完成它。它在 /Library/Preferences/com.apple.LaunchServices.plist中添加了一个条目。但是文件不会使用指定的应用程序打开。

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

3 个解决方案

#1


5  

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.

也许你没有做错,但只需要重新加载com.apple.launchservices文件。您可以注销,等待几分钟或强制启动服务重新启动。在下面的示例中,我说public.comma-separated-values-text文件(注意:这并不意味着每个CSV文件都是此内容类型)必须使用TextEdit而不是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"

#2


0  

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"

在文件上,选择“获取信息”,然后在“打开方式”下选择应用程序的名称。点击“全部更改”按钮

#3


0  

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.

您可能想看看RCDefaultApp及其源代码。这是一个程序,可让您设置哪些文件类型由Launch Services中的哪些应用程序打开。

#1


5  

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.

也许你没有做错,但只需要重新加载com.apple.launchservices文件。您可以注销,等待几分钟或强制启动服务重新启动。在下面的示例中,我说public.comma-separated-values-text文件(注意:这并不意味着每个CSV文件都是此内容类型)必须使用TextEdit而不是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"

#2


0  

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"

在文件上,选择“获取信息”,然后在“打开方式”下选择应用程序的名称。点击“全部更改”按钮

#3


0  

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.

您可能想看看RCDefaultApp及其源代码。这是一个程序,可让您设置哪些文件类型由Launch Services中的哪些应用程序打开。