简体   繁体   English

在MacOSX上抓取openFileEvent(无法获取文件名)

[英]Grabbing the openFileEvent on MacOSX (Can't get filename)

We have a Java app on the Mac set to where you double click our custom extension, it opens the app, and then the app does work on the file you clicked. 我们在Mac上设置了一个Java应用程序,您可以在其中双击我们的自定义扩展程序,它会打开应用程序,然后该应用程序可以对您单击的文件进行操作。 The problem is that I cannot get the "open event" that apple uses in OSX, and so I cannot get the filename (and location) to do the work on. 问题是我无法获得苹果在OSX中使用的“开放事件”,因此我无法获得文件名(和位置)来完成工作。 I tried everything I could find using Google, so I must be doing something inherently wrong. 我尝试了使用谷歌找到的所有东西,所以我必须做一些内在错误的事情。

Here is the class I call right at the start the application. 这是我在应用程序启动时调用的类。 I just make a new class, and then grab the files a few lines after. 我刚刚创建了一个新类,然后在几行之后抓取文件。 I have also tried to put a wait/notify all to see if it was a timing issue, however it would just wait indefinitely so I think it is a problem with the way I am actually capturing the event. 我还尝试了等待/通知所有人,看看它是否是一个时间问题,但是它会无限期地等待,所以我认为这是我实际捕获事件的方式的问题。 Any help at all would be useful. 任何帮助都是有用的。

import java.io.File;
import java.util.List;

import com.apple.eawt.AppEvent.OpenFilesEvent;
import com.apple.eawt.Application;
import com.apple.eawt.OpenFilesHandler;

public class MacFiles implements OpenFilesHandler{

    private List<File> files;

    public MacFiles() {
        Application.getApplication().setOpenFileHandler(this);
    }

    public List<File> getFiles() {
        return files;
    }

    public void openFiles(OpenFilesEvent event) {
    files = event.getFiles();
    }
}

您是否编辑过Info.plist,包括CFBundleDocumentTypesUTExportedTypeDeclarations

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM