标签:apple macos objective-c xcode applescript
以下这条Apple Script可以用管理员身份去执行一个命令或程序, 权限是继承的。
do shell script "chmod 777 /tmp" with administrator privileges
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!"); }
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!"); }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:apple macos objective-c xcode applescript
原文地址:http://blog.csdn.net/sysprogram/article/details/46910965