javamacosjavafxmacos-big-surlaunch-services

Opening app on macOS 11 Big Sur from JavaFX application randomly fails with kLSNoExecutableErr


We have a desktop JavaFX application (well, TornadoFX) that downloads an archive, extracts another app from it and launches this app with macOS open command. Simplified kotlin code looks like:

ProcessBuilder(listOf("open", "/path/to/app.app", "arg")).start()

This has worked for years on older versions of macOS (10.15 and earlier) but now with macOS 11 Big Sur launching the app sometimes succeeds and sometimes fails.

In the mac Console.app following error can be seen:

OSStatus _LSCopyApplicationNodeFromOpenState(LSOpenState *): Returning kLSNoExecutableErr because node is a directory but we failed to register with error -10814

We extended the logic to check if all the files are really there before launching the app, and the files existed.

There is an assumption that maybe Launch Services database is not updated fast enough.

Following ways of trying to log what might be happening, didn't reveal any errors:

lsappinfo listen +all forever

log stream --debug --predicate 'subsystem == "com.apple.coreservices.launchservices"'

Does anybody have a clue if there is a way to avoid this behavior and to be always able to launch the app?


Solution

  • After a lot of research and debugging, what seem to have worked for us, was to force Launch Services to register the app in its database by executing command like:

    /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f /path/to/app.app

    and afterwards we could launch the app.

    The idea for such solution was found in this answer.