如何在 Mac OS X 中为特定文件类型设置默认应用程序?
在 Mac OSX lion 中,我尝试为特定文件类型设置默认应用程序。 使用下面的苹果脚本,我们可以为特定的“file.abc”设置默认应用程序。
tell application "System Events"
set default application of file "/Users/test/Desktop/file.abc" to "/Applications/TextEdit.app"
end tell
但我想为所有文件类型或扩展名为“abc”的文件设置相同的应用程序作为默认应用程序。
我已尝试以下方法来完成它。它在
中添加了一个条目。但这些文件不是用指定的应用程序打开的。
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>"
希望有人知道我缺少什么来实现它。
找到答案:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许您没有做错什么,但 com.apple.launchservices 文件只需要重新加载。您可以注销、等待几分钟或强制重新启动启动服务。在下面的示例中,我说 public.comma-separated-values-text 文件(注意:这并不意味着每个 CSV 文件都是这种内容类型)必须使用 TextEdit 而不是 Excel 打开。
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.
我不确定您是否只是想以编程方式执行此操作。你是?
否则:
在文件上,选择“获取信息”,然后在“打开方式”下选择应用程序的名称。
单击“全部更改”按钮
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"
您可能想查看 RCDefaultApp 及其源代码。它是一个程序,可让您设置启动服务中的哪些应用程序打开哪些文件类型。
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.