Why is applicationDidFinishLaunching not called when using an ssh connection to the MacOS machine

Hello,

We created a sample app delegate to test whether applicationDidFinishLaunching runs as expected or not (code as follows). The observed behavior was that the executable

  1. prints both applicationWillFinishLaunching and applicationDidFinishLaunching in the case when we're using an RDP connection to the mac
  2. prints only applicationWillFinishLaunching in case of ssh connection to the mac

Why is this behavior different and how can I ensure it runs correctly with ssh? Kindly help.

#include    <unistd.h>
#include    <sys/types.h>
#include    <Foundation/Foundation.h>
#import     <Cocoa/Cocoa.h>
#import     <SystemConfiguration/SystemConfiguration.h>
#import     <SystemConfiguration/SCDynamicStore.h>

@interface TWAppKitAppDelegate : NSObject <NSApplicationDelegate>

@end


@implementation TWAppKitAppDelegate

// Launching Applications

- (void)
applicationWillFinishLaunching: (NSNotification *) pNotification 
{
   NSLog(@"applicationWillFinishLaunching");

}

- (void)
applicationDidFinishLaunching: (NSNotification *) pNotification 
{

   NSLog(@"applicationDidFinishLaunching");

}

// Managing Active Status

- (void)
applicationWillBecomeActive: (NSNotification *) pNotification 
{
}

- (void)
applicationDidBecomeActive: (NSNotification *) pNotification 
{

}

- (void)
applicationWillResignActive: (NSNotification *) pNotification 
{
}

- (void)
applicationDidResignActive: (NSNotification *) pNotification 
{
}

// Terminating Applications

#if 0
- (NSApplicationTerminateReply)
applicationShouldTerminate:(NSNotification *) pNotification 
{

    return NSApplicationTerminateReply::NSTerminateNow;
}
#endif 

- (BOOL)
applicationShouldTerminateAfterLastWindowClosed:(NSNotification *) pNotification 
{

    return NO;
}

- (void)
applicationWillTerminate:(NSNotification *) pNotification 
{

}

- (BOOL)
application:(NSApplication *) pSender
openFile:   (NSString *) pFileName
{
   return YES;
}

- (void)
application:(NSApplication *) pSender
openFiles:  (NSArray<NSString *> *) pFileNames
{
}

@end

int 
main (int pArgc, char ** pArgv) 
{

        NSApplication *         app;
        TWAppKitAppDelegate *   appdelegate;

       app = [NSApplication sharedApplication];

       appdelegate = [[TWAppKitAppDelegate alloc] init];

       [app setDelegate:appdelegate];
       
       [NSApp run];    //NOTE: Apple never 'returns' from here

       NSLog(@"Function main called \n");

  return 0;
}

I’m helping ask_apple07 in a different context but I wanted to post a quick response here: When you log in via SSH your shell is running in a non-GUI context. Running GUI apps in a non-GUI context is not supported and it can result in all sorts of weird and wonderful problems. Don’t do that!

To learn more about execution contexts on macOS, see Technote 2083 Daemons and Agents.

Share and Enjoy

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

Why is applicationDidFinishLaunching not called when using an ssh connection to the MacOS machine
 
 
Q