Created
November 5, 2010 13:43
-
-
Save glejeune/664178 to your computer and use it in GitHub Desktop.
Execute with Root privileges
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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