Jump to content

Run script with sudo and output?


Recommended Posts

Hi,

 

I'm trying to run this script using Alfred https://github.com/tjluoma/sudo-via-touch-id/blob/main/sudo-via-touch-id.sh

 

But the debug says sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper

Running the script manually prompts for the password but not when using Alfred to run it. I dont know where to configure the -S or askpass helper...

 

Also after running the script it outputs what is changed, how to get this result shown what was done by the script?

sudo-via-touch-id [SUCCESS]: 'sudo' was successfully added to '/etc/pam.d/sudo'.
sudo-via-touch-id: 'iTerm' preference is already set properly.

 

Thanks in advance

 

 

Link to comment

You’re getting the message because sudo is interactive (you have to type the password) but the running of the script isn’t. There are a few ways around it, but the shortest and more interesting is (change the Language in the Run Script to /usr/bin/osascript (AppleScript) and replace /PATH/TO/SCRIPT with the correct location):


do shell script "/PATH/TO/SCRIPT" with administrator privileges

 

It will ask you for Touch ID identification to run the script and the sudo will be taken care of.

 

Though why try running the script in Alfred? Running that should be a one-time thing.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...