STPrivilegedTask icon indicating copy to clipboard operation
STPrivilegedTask copied to clipboard

Trying to create a Platypus-Like App that runs as launchd startup.

Open peetinc opened this issue 5 years ago • 0 comments

Catalina blocks any Platypus-built apps I try to use as a LaunchDaemon/LaunchAgent (at the login window). Something just stops them from firing. See here.

I 'wrote' a simple app to just launch a 'script' file in resources. It works and will be adequate, but I'd very much like to double-click, authenticate as an admin and have it run as root ...

#import <Cocoa/Cocoa.h>
#import "STPrivilegedTask.h"

int main(int argc, const char * argv[]) {
@autoreleasepool {
    NSTask *script = [[NSTask alloc] init];
    [script setLaunchPath:@"/bin/zsh"];
    [script setArguments:@[ [[NSBundle mainBundle] pathForResource:@"script" ofType:nil] ]];
    [script launch];
}
   return 0;
}

I have virtually no Objective-C or coding experience beyond shell scripting, but I'm trying. My hope was to have something like this,

#import <Cocoa/Cocoa.h>
#import "STPrivilegedTask.h"

int main(int argc, const char * argv[]) {
@autoreleasepool {
    
   STPrivilegedTask *privilegedTask = [[STPrivilegedTask alloc] init];
   [privilegedTask setLaunchPath:@"/bin/zsh"];
   [privilegedTask setArguments:@[@"script"]];
  
   // Setting working directory is optional, defaults to /
   NSString *path = [[NSBundle mainBundle] resourcePath];
   [privilegedTask setCurrentDirectoryPath:path];
  
   // Launch it, user is prompted for password
   OSStatus err = [privilegedTask launch];
   if (err == errAuthorizationSuccess) {
       NSLog(@"Task successfully launched");
   }
   else if (err == errAuthorizationCanceled) {
       NSLog(@"User cancelled");
   }
   else {
       NSLog(@"Something went wrong");
   }
  
}
   return 0;
}

But this will not pop an authorization for the end user and always returns

2020-02-25 18:05:45.569310-0700 Remote Acccess[33288:288320] Something went wrong

I'm sure I'm missing something that is blatantly obvious to anyone who knows what they are doing.

Thanks for any help.

peetinc avatar Feb 26 '20 01:02 peetinc