簡體   English   中英

使用JavaStub的不帶Java應用程序捆綁的OSX上的文件關聯

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

我有一個不使用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腳本) 。

為此,您不能使用shell腳本AFAIK。 使用AppleEvents發送已打開的文件,而bash無法接收這些文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM