0

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 .

user12345
  • 425
  • 1
  • 3
  • 14

2 Answers2

0

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
regulus6633
  • 18,848
  • 5
  • 41
  • 49
  • I added the line what you suggested in a script and called that script through NSTask . The GUI hangs after asking the password.In GDB i can see YES(0) . – user12345 Dec 13 '12 at 14:38
  • I never used this so you'll have to play with it to get it to work right. Google for examples. – regulus6633 Dec 13 '12 at 18:19
0

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.

user12345
  • 425
  • 1
  • 3
  • 14