Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not pass Apple Event "Open File" to Java application #1

Open
eduardomozart opened this issue Apr 6, 2023 · 3 comments
Open

Do not pass Apple Event "Open File" to Java application #1

eduardomozart opened this issue Apr 6, 2023 · 3 comments

Comments

@eduardomozart
Copy link

eduardomozart commented Apr 6, 2023

Hello,
When using JavaMacLauncher as a Java stub, when using Info.plist to associate a extension with the program (e.g. *.por files), when clicking into a *.por file, it opens the Java program but it didn't pass the file path as an argument to the Java program.
In AppleScript, it's possible to intercept them using "On Open", that receives kAEOpenDocuments (Apple Events), as "Open With" actions do not pass them as arguments (argv) to the executable, instead, it passes the files to open as an Apple Event. There's a workaround in https://github.com/RichardBronosky/AppleScript-droplet which receive those events and bypass them to the Bash script as arguments.

@fvarrui
Copy link

fvarrui commented Sep 19, 2024

I get the File this way when double-clicking on Mac OS:

public class MyClass {

    private static String[] args;

    public static void main(String[] args) {

        if (System.getProperty("os.name").contains("OS X")) {
            java.awt.Desktop.getDesktop().setOpenFileHandler((java.awt.desktop.OpenFilesEvent e) -> {
                File f = e.getFiles().stream().findFirst().get();
                MyClass.args = new String[] { f.getAbsolutePath() };
            });
        }

    }

}    

A bit late, but I hope it helps!

@eduardomozart
Copy link
Author

It would be great if no changes to the source code be necessary. JavaMacLauncher should handle those scenarios and convert them as in-line arguments to the program so it would work as it is as on other platforms (Windows, Linux...).

@fvarrui
Copy link

fvarrui commented Sep 19, 2024

It would be great if no changes to the source code be necessary. JavaMacLauncher should handle those scenarios and convert them as in-line arguments to the program so it would work as it is as on other platforms (Windows, Linux...).

Yes, I agree! It would also be great if there was a version of JavaMacLauncher for ARM64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants