1

我有一个用于 Java 应用程序的 OSX App-Bundle,它不使用 Java-Stub,而是一个 Shellscript(通过 Info.plist 注册)。我还在 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>
…

这是让 LaunchService 识别我的文件以及与我的程序的关联所需要的。

据我了解 Apple Devel 文档,我现在需要在 Java 中注册文件打开处理程序,以便通过将文件拖到 App-Icon 上来打开文件,如下所示(从 Java 6 更新 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 );
                }
            }
        } );

我的第一个问题是:这个处理程序永远不会被击中 - 没有调试消息并且文件不会打开。

第二个问题可能与此有关:我可以双击关联的文件,如果没有运行,应用程序将打开。由于我使用自定义 shell 脚本来启动应用程序,因此我认为我必须添加某种参数左右。首先这是我的启动脚本:

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

出于测试目的,我将“$1”添加到我的参数列表中 - $1 是系统中的 PSN ......我如何将文件打开事件连接到 PSN - 或者是否有其他方法可以做到这一点(使用自定义 shell 脚本) .

4

1 回答 1

0

你不能为此使用shell脚本,AFAIK。打开的文件是使用 AppleEvents 发送的,而 bash 没有办法接收这些文件。

于 2011-03-31T09:17:08.877 回答