在MacOSX上获取openFileEvent(无法获取文件名) [英] Grabbing the openFileEvent on MacOSX (Can't get filename)

查看:158
本文介绍了在MacOSX上获取openFileEvent(无法获取文件名)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在Mac上有一个Java应用程序,您可以在其中双击自定义扩展名,将其打开,然后该应用程序即可在您单击的文件上运行.问题是我无法获得Apple在OSX中使用的打开事件",因此无法获得文件名(和位置)来进行工作.我尝试使用Google可以找到的所有内容,因此我必须做一些天生的错误.

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. 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. 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吗?

Have you edited the Info.plist, including both CFBundleDocumentTypes and UTExportedTypeDeclarations ?

这篇关于在MacOSX上获取openFileEvent(无法获取文件名)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆