Sorry, you canβt. Because no password is entered.
However, you can still run the bash command using NSAppleScript
instead of NSTask
: Write an application like:
do shell script
[your command]
with administrator privileges
You will be prompted for an administrator password.
Example:
NSDictionary *error = [NSDictionary new]; NSString *script = @"do shell script \"launchctl load /Users/admin/Library/LaunchAgents/com.devdaily.crontabtest.plist\" with administrator privileges"; NSAppleScript *appleScript = [[NSAppleScript new] initWithSource:script]; if ([appleScript executeAndReturnError:&error]) { NSLog(@"success!"); } else { NSLog(@"failure!"); }
source share