问题描述
我有一个不使用Java-Stub的Java应用程序的OSX应用程序捆绑包,而是一个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 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 );
}
}
} );
我的第一个问题是:此处理程序永远不会被命中-没有调试消息,并且文件也不会打开。
第二个问题可能与该问题有关:我可以双击关联的文件,如果未运行,则该应用程序将打开。 由于我使用自定义外壳脚本来启动应用程序,因此我认为我必须添加某种参数。 首先,这是我的开始脚本:
#!/bin/bash
BASEDIR=$(dirname "$0")
cd "$BASEDIR/../Resources/Java/"
java -Xdock:icon="../ico.icns" -Xmx256m -jar "core/myjar.jar"
出于测试目的,我在参数列表中添加了“ $ 1”-$ 1是系统中的PSN…我如何将文件打开事件连接到PSN-还是有另一种方法来做到这一点(使用自定义Shell脚本) 。
1楼
为此,您不能使用shell脚本AFAIK。 使用AppleEvents发送已打开的文件,而bash无法接收这些文件。