The following Apple script can be used as an administrator to execute a command or program with inherited permissions.
Do shell script ' chmod 777/tmp ' with administrator privileges
You can do it in objective-c.
Nsdictionary *error = [nsdictionary new]; NSString *script = @ "do shell script \" chmod 777/tmp\ "with administrator privileges"; Nsapplescript *applescript = [[Nsapplescript alloc] initwithsource:script]; if ([AppleScript Executeandreturnerror:&error]) { NSLog (@ "sucess"); } else { NSLog (@ "fail!"); }
Use WhoAmI to get the current permissions, output to the/tmp/me file
Nsdictionary *error = [nsdictionary new]; NSString *script = @ "do shell script \" WhoAmI >/tmp/me\ "with Administrator privileges"; Nsapplescript *applescript = [[Nsapplescript alloc] initwithsource:script]; if ([AppleScript Executeandreturnerror:&error]) { NSLog (@ "sucess"); } else { NSLog (@ "fail!"); }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
AppleScript running the program as an administrator