Question

I have a MAC OSX cocoa application,where i used NSAppleScript to run some script with administrator privileges .The application works fine when it is launched manually or from any other script .

But NSAppleScript doesn't launch the intended script when i tried to launch the application from package maker .

I have made a postflight script to launch the application from package maker .

Postflight:

#!/bin/sh open pathOFApp

NSAppleScript usage:

NSDictionary *error = [NSDictionary new];


NSAppleScript *appleScript = [[NSAppleScript new] initWithSource:@"do shell script \"pathOFScript \" with administrator privileges"];

if ([appleScript executeAndReturnError:&error]) {
          NSLog(@"-----success --------");

}

else{
    NSLog(@"-------Failure-----");

}

Please help to fix this .

Was it helpful?

Solution

I don't know the answer with applescript/PackageMaker, but have you tried using the unix security tool to launch your executable? I think it's been available since 10.5. You can probably combine this and your executable in one statement too.

/usr/bin/security execute-with-privileges /path/to/executable

OTHER TIPS

Got the solution for this .Since postflight script is launched with the root permission by packageMaker it was creating some permission issue with the NSAppleScript . Launching the application as "sudo open MyApp" in postflight will resolve the issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top