'open' command in macOS fails to launch .app file in non GUI environment

I have a bundled application(.app file) in macOS which is a non-interactive application. This app does not link to any GUI frameworks and I am able to launch it using the 'open' command in a normal GUI login session.

However, when I perform ssh login to that user and then If I try to launch the application, it fails to launch.

I assume that this is happening because my ssh session is a non-GUI session, and 'open' command is due to some reason failing to run in a non-GUI environment, but I m not sure.

Can someone help me understand why is this happening?

Essentially this is because open itself isn’t rated for use in a non-GUI context. Consider:

% otool -L `which open`
/usr/bin/open:
    …
    /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit …
    …

It is essentially a wrapper around NSWorkspace.

Can you explain more about the big picture here? How have you found yourself in a situation where you need to do this?

For… ahem… context, I recommend that you read the Execution Contexts section of Technote 2083 Daemons and Agents.

As explained in that technote, it’s not possible for code to change its execution context. There are limited circumstances where it makes sense for program A to run program B in a different execution context. However, it’s generally better if you can arrange for the system to run program B in that context in the first place. But the best way to do that depends on how your product is structured.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

'open' command in macOS fails to launch .app file in non GUI environment
 
 
Q