I have a shell script that adds a line to /etc/hosts. If I run it manually with sudo, it works correctly. I'd like to distribute this file to my coworkers who use Macs. However, when the shell script runs normally, I get a:
sed: /etc/hosts: Permission denied
Is there a way to force a bash script to prompt for a password, as compiled ObjC code can do? If Bash can't do this, can Applescript do so?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With