@@ -35,8 +35,27 @@ public void launch() {
3535 }
3636 ProcessBuilder pb ;
3737 if (System .getProperty ("os.name" ,"" ).toLowerCase ().contains ("mac" )) {
38- // macOS: use open command to properly register with window server
39- pb = new ProcessBuilder ("open" , "-W" , "-n" , "-a" , exeToRun .getAbsolutePath ());
38+ // macOS: wrap in minimal .app bundle so the process gets window server access
39+ java .io .File appBundle = new java .io .File (sketchFolder , exeToRun .getName () + ".app" );
40+ java .io .File macosDir = new java .io .File (appBundle , "Contents/MacOS" );
41+ macosDir .mkdirs ();
42+ java .io .File bundledBin = new java .io .File (macosDir , exeToRun .getName ());
43+ java .nio .file .Files .copy (exeToRun .toPath (), bundledBin .toPath (),
44+ java .nio .file .StandardCopyOption .REPLACE_EXISTING );
45+ bundledBin .setExecutable (true );
46+ // Write minimal Info.plist
47+ java .io .File plist = new java .io .File (appBundle , "Contents/Info.plist" );
48+ java .nio .file .Files .writeString (plist .toPath (),
49+ "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n "
50+ + "<!DOCTYPE plist PUBLIC \" -//Apple//DTD PLIST 1.0//EN\" \" http://www.apple.com/DTDs/PropertyList-1.0.dtd\" >\n "
51+ + "<plist version=\" 1.0\" ><dict>\n "
52+ + "<key>CFBundleExecutable</key><string>" + exeToRun .getName () + "</string>\n "
53+ + "<key>CFBundleIdentifier</key><string>processing.cpp." + exeToRun .getName () + "</string>\n "
54+ + "<key>CFBundleName</key><string>" + exeToRun .getName () + "</string>\n "
55+ + "<key>NSHighResolutionCapable</key><true/>\n "
56+ + "<key>NSPrincipalClass</key><string>NSApplication</string>\n "
57+ + "</dict></plist>\n " );
58+ pb = new ProcessBuilder ("open" , "-W" , "-n" , appBundle .getAbsolutePath ());
4059 } else {
4160 pb = new ProcessBuilder (exeToRun .getAbsolutePath ());
4261 }
0 commit comments