Capture openFileEvent on MacOSX (unable to get file name)

We have a Java application on Mac, where you double-click on our custom extension, it opens the application, and then the application works on the file that you clicked. The problem is that I cannot get the “open event” that Apple uses on OSX, and therefore I cannot get the file name (and location) to do this work. I tried everything I could find with Google, so I have to do something inherently wrong.

Here is the class that I call at the beginning of the application. I just create a new class and then grab the files in a few lines. I also tried putting wait / notify everything to see if it was a time problem, however it would just wait indefinitely, so I think it is a problem with how I really capture the event. Any help at all would be helpful.

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();
    }
}
+3
source share
1 answer

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

0
source

Source: https://habr.com/ru/post/1533855/


All Articles