Skip to content

Instantly share code, notes, and snippets.

@glejeune
Created November 5, 2010 13:43
Show Gist options
  • Save glejeune/664178 to your computer and use it in GitHub Desktop.
Save glejeune/664178 to your computer and use it in GitHub Desktop.
Execute with Root privileges
- (void)execute:(NSString *)cmd {
NSString *appScript = [NSString stringWithFormat:@"do shell script \"%@\" with administrator privileges", cmd];
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:appScript];
NSDictionary *errorInfo = nil;
NSAppleEventDescriptor *data = [script executeAndReturnError:&errorInfo];
if( data == nil ) {
// Hum... Something happend, dude!
NSLog(@"ERROR : %@", [errorInfo objectForKey:NSAppleScriptErrorMessage]);
} else {
// Good job!
NSLog(@"OK: %@",[data stringValue]);
}
[script release];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment