Reputation: 2792
How can I associate a file type like .vlan in mac within java code?
Runtime.getRuntime().exec("defaults write com.apple.LaunchServices LSHandlers -array-add
\"<dict><key>LSHandlerContentTag</key>
<string>.vlan</string><key>LSHandlerContentTagClass</key>
<string>public.filename-extension</string><key>LSHandlerRoleAll</key>
<string>org.category.program</string></dict>\"");
Upvotes: 0
Views: 215
Reputation: 17697
Try this :
Runtime.getRuntime().exec(
new String[] {
"defaults",
"write",
"com.apple.LaunchServices",
"LSHandlers",
"-array-add",
"<dict><key>LSHandlerContentTag</key><string>.vlan</string><key>LSHandlerContentTagClass</key><string>public.filename-extension</string><key>LSHandlerRoleAll</key><string>org.category.program</string></dict>"
}
);
And just to add, Runtime's exec has quite some pitfalls one need to be aware of.
Upvotes: 1
Reputation: 168835
If the app. has a GUI, deploy it using Java Web Start and declare the file extension/type in the JNLP (launch) file. Here is a demo. of the JNLP API file services which should be able to associate the text/sleepytime
content type of .zzz
file with the (small) app.
Adding an association for a file type is supported to work on Windows, OS X & *nix (for all permissions, as well as sand-boxed apps. (the latter prompted)).
Upvotes: 1