That command should be put into the pmset file created with visudo, replacing the line from before. It's basically replacing my "let me do everything with pmset without asking for a password" with "let me do this specific thing with pmset without asking for a password".
As @peternlewis said -- much better practice to allow only what is necessary, and no more.
Trying to use this to automate changes to scheduled wake times by running this shell script after setting the variable wakeTime with a prompt–
sudo pmset repeat wake MTWThFSSu %Variable%wakeTime%:00
I have so far unsuccessfully tried these variations of Peter's solution:
my_username ALL= NOPASSWD: /usr/bin/pmset -a wake 10, !/usr/bin/pmset -a wake 10 *
my_username ALL= NOPASSWD: /usr/bin/pmset -a repeat wake 10, !/usr/bin/pmset -a repeat wake 10 *
my_username ALL= NOPASSWD: /usr/bin/pmset -a pmset repeat wake 10, !/usr/bin/pmset -a pmset repeat wake 10 *
my_username ALL= NOPASSWD: /usr/bin/pmset -a sudo repeat wake 10, !/usr/bin/pmset -a sudo repeat wake 10 *
my_username ALL= NOPASSWD: /usr/bin/pmset -a sudo pmset repeat wake 10, !/usr/bin/pmset -a sudo pmset repeat wake 10 *
I then press esc, :wq, return, and try to run the shell script, getting this error:
Execute a Shell Script failed with script error: sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
sudo: a password is required. Macro “Trying” cancelled (while executing Set schedule).
I know virtually nothing about using the terminal etc. This is my first time making a macro with a shell script. So, noob questions-
Is it the very top line of the sudo visudo file that I insert this? i.e., above all the lines that start with "# Sample /etc/sudoers file.”?
Is a restart required for changes to take effect?
@peternlewis If you happen to have time, do you know what the correct version of your solution would look like for this function?
Thank you so much Peter! That got me very close and it was just a couple adjustments from there and now it all works perfectly.
For anyone's future reference, what ended up working was:
my_username ALL=(ALL) NOPASSWD: /usr/bin/pmset repeat wake *
Also, chatGPT suggested I had been putting it in the wrong place in the sudoers file, so I moved it from the top line to the bottom line. Once I did that, I stopped getting the 'needs password' error and started getting a 'badly formatted power command' error. I eventually realized thatI shouldn't have been putting token text in a shell script action, so looked it up on the KM wiki and quickly found the answer was to change it to:
sudo pmset repeat wake MTWThFSSu $KMVAR_wakeTime:00