OSX 上的文件关联,用于不使用 JavaStub 的 Java 应用程序包
我有一个用于 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 中注册文件打开处理程序,以便通过将文件拖到应用程序图标上来打开文件,如下所示(从 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 脚本)。
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 have 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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AFAIK,你不能为此使用 shell 脚本。打开的文件是使用 AppleEvents 发送的,而 bash 没有办法接收这些文件。
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.