简体   繁体   中英

File association in Mac

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM