Handling Opening Files

Ivan Nikitin ivan at nikitin.io
Mon May 5 07:13:56 UTC 2014


Hi Joshua,

We also have Document types record in the Info.plist file of our bundle:

<array>
<dict>
<key>CFBundleTypeName</key>
<string>Images</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>public.image</string>
</array>
<key>NSExportableTypes</key>
<array>
<string>public.image</string>
</array>
</dict>
<dict>
<key>CFBundleTypeName</key>
<string>Folders</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>None</string>
<key>LSItemContentTypes</key>
<array>
<string>public.folder</string>
</array>
</dict>
</array>

This is a list of file types the app can handle. With it open file 
handler is called correctly. We're using OpenJDK 7u45.

Joshua Smith wrote:
> I’ve finally bitten the bullet and moved over to Java 7 on Mac.
>
> The only thing I’m stuck on is handling opening files when they are double-clicked in the Finder or dropped on my program in the Dock.
>
> Are there any changes required to the file handling stuff in Info.plist for Java 7, or should one that worked with the previous Java still work?
>
> Previously, I had this to handle the files:
>
>          com.apple.mrj.MRJApplicationUtils.registerOpenDocumentHandler(m);
>
> Some googling revealed that now I need this:
>
>          com.apple.eawt.Application.getApplication().setOpenFileHandler(m);
>
> Double-clicking the file is opening my app, but the OpenFileHandler is never called.
>
> (Note that Application.getApplication().addApplicationListener(m) *is* working; I’m able to intercept Quit like I used to.)
>
> If my program was not running, it opens. But no handler call.
>
> If my program was already running, it pops to the foreground. But no handler call.
>
> What’s the trick?
>
> -Joshua
>
>

-- 
Ivan Nikitin



More information about the macosx-port-dev mailing list