From a bash script in OS X, is it possible to prompt for Administrator permissions? From a bash script in OS X, is it possible to prompt for Administrator permissions? bash bash

From a bash script in OS X, is it possible to prompt for Administrator permissions?


Adayzdone's answer is a correct way to use "with administrator privileges"

But you do not need to hard code password or create your own dialog.

If you do not include the user name and password you will be prompted with the standard username and password dialogue for an admin.

do shell script "echo hi" with administrator privileges


your shell script can call sudo which would ask at terminal for a password.

Try http://www.performantdesign.com/2009/10/26/cocoasudo-a-graphical-cocoa-based-alternative-to-sudo/

#!/usr/bin/env bashif [ "$SUDO_USER" ]then  sed `do stuff`else     cocoasudo --prompt="Please authenticate" bash -l -c "/path/to/this/script"fi


With Applescript:

property usr : "username"property pswd : "password"do shell script "echo hi" user name usr password pswd with administrator privileges

Or if you don't want to hard code the password:

set usr to text returned of (display dialog "Enter username" default answer "my username")set pswd to text returned of (display dialog "Enter password…" default answer "my password")do shell script "echo hi" user name usr password pswd with administrator privileges