File association in Mac

人盡茶涼 提交于 2019-12-02 11:52:01

问题


Finding help from here we are now able create a Mac application from a jar file and associate the application with certain file extension .

When double click a file with that extension it is opening in that application and ultimately in the embedded java application.

However our need is to get the selected file path as an argument to the main method of the java application. How can we achieve this. for file type association we have used

defaults write com.apple.LaunchServices LSHandlers -array-add 

<dict>
  <key>LSHandlerContentTag</key>
  <string>PUT_FILE_EXTENSION_HERE_WITHOUT_PERIOD</string>
  <key>LSHandlerContentTagClass</key>
  <string>public.filename-extension</string>
  <key>LSHandlerRoleAll</key>
  <string>org.category.program</string>
</dict>

with changes.

Should there be any change in the Info.plist file?


回答1:


Use Java Web Start to declare the interest in that file-type. Here is a demo of the JNLP file services that associates the .zzz file-type with the app. This approach should work for OS X (& Windows, & *nix).




回答2:


Apple provides some specific classes that allow you to better incorporate Java applications into Mac OS X. Google for "Apple Java eawt", or try this link: http://developer.apple.com/library/mac/documentation/Java/Reference/JavaSE6_AppleExtensionsRef/api/com/apple/eawt/package-summary.html. Look especially for the Application- and ApplicationAdapter-Class (reps. their not-deprecated parts). you can register special listeners to get the information about files that should be opened.



来源:https://stackoverflow.com/questions/9096991/file-association-in-mac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!