3

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();
    }
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Greg W.
  • 51
  • 2
  • Deploy the app. using [Java Web Start](http://stackoverflow.com/tags/java-web-start/info). JWS allows declaring an interest in a file type within the JNLP (a JWS launch file). The file name(s) will be passed to main. This [demo.](http://pscode.org/jws/api.html#fs) declares an interest in the `.zzz` file type. This should work on OS X as well as Windows and *nix. – Andrew Thompson Feb 10 '12 at 15:40

1 Answers1

0

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

Black
  • 5,023
  • 6
  • 63
  • 92