开发者

File Association on OSX for Java Application Bundle w/o using JavaStub

开发者 https://www.devze.com 2023-02-21 04:35 出处:网络
I have an OSX App-Bundle for a Java Application that does not use the Java-Stub, but a Shellscript (registered via Info.plist). I also registered my file extension in the Info.plist:

I have an OSX App-Bundle for a Java Application that does not use the Java-Stub, but a Shellscript (registered via Info.plist). I also registered my file extension in the Info.plist:

…
<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>My File Type Name</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>ext1</string>
            <string>ext2</string>
        </array>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleTypeMIMETypes</key>
        <array>
            <string>application/ext1</string>
            <string>application/ext2</string>
        </array>
    </dict>
</array>
…

This is what was needed to have the LaunchService recognize my files and the association to my program.

As far as I understand the Apple Devel docs I now need to register the file open Handler in Java to have the files opened by dragging them onto the App-Icon like so (as of Java 6 update 3):

        Application.getApplication().setOpenFileHandler( new OpenFilesHandler() {

            @Override
            public void openFiles( OpenFilesEvent arg0 ) {
                Debug.debug( "Opening a bunch of files on osx." );
                for( File file : arg0.getFiles() ) {
                    Debug.debug( "Opening: " + file.getAbsolutePath() );
                    // Custom open action
                    FileActions.openFile( file );
                }
            }
        } );

My first problem is: This Handler never gets hit - there is no Debug message and the files won't open.

The second problem may be related: I can double click the associated file and the App will open if not running. Since I'm using a custom shell script to start the app I thought I'd ha开发者_运维知识库ve to add some kind of parameter or so. First this is my startscript:

#!/bin/bash
BASEDIR=$(dirname "$0")
cd "$BASEDIR/../Resources/Java/"
java -Xdock:icon="../ico.icns" -Xmx256m -jar "core/myjar.jar"

For testing purpose I added "$1" to my arguments list - $1 is the PSN from the system … How would I connect the Event of file opening to the PSN - or is there another way to do just that (using the custom shell script).


You can't use a shell script for this, AFAIK. Opened files are sent using AppleEvents, and bash does not have a way to receive those.

0

精彩评论

暂无评论...
验证码 换一张
取 消