2023 9/27 edit:
if anyone knows how to configure Gordon Davisson's answer with Touch ID, that would fully resolve this post.
2023年9月27日编辑:如果有人知道如何用Touch ID配置Gordon Davisson的答案,那就完全可以解决这篇帖子了。
2023 9/9 original post:
why might this not be working anymore?
did something change with background Terminal password prompting?
2023年9月9日原帖子:为什么这可能不再工作了?后台终端密码提示有什么变化吗?
for a few months now, I've used a script to put my macbook to sleep. I normally have sleep disabled so that I can close the lid without stopping anything or locking anything.
几个月来,我一直在使用一个脚本让我的MacBook进入睡眠状态。我通常会禁用睡眠,这样我就可以在不停止任何东西或锁住任何东西的情况下关闭盖子。
this worked fine until today. I now receive :
'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'
直到今天,这一切都运行得很好。我现在收到:‘sudo:需要终端来读取密码;要么使用-S选项从标准输入中读取,要么配置askpass助手sudo:需要密码。’
previously the script was able to trigger a user prompt itself, and I had that set to allow fingerprint authorization. so I could simply activate the script, touch the touch sensor, and be on my way.
以前,该脚本能够自己触发用户提示,我将其设置为允许指纹授权。所以我可以简单地激活脚本,触摸触摸传感器,然后就可以上路了。
the full script is :
全文如下:
do shell script "sudo pmset -a disablesleep 0"
tell application "System Events" to sleep
do shell script "sudo pmset -a disablesleep 1"
and is wrapped as an app in my Applications folder.
并被包装为我的应用程序文件夹中的一个应用程序。
I tried using sudo -S pmset
but that seems to be for piping in the password from somewhere else or some other kind of prompt.
I believe that's the wrong thing because I want it to do what it did before.
which I think was prompting through the terminal.
我尝试使用sudo-S pmset,但这似乎是为了从其他地方输入密码或某种其他类型的提示。我认为这是错误的,因为我希望它能像以前一样。我认为这是通过航站楼提示的。
更多回答
优秀答案推荐
I'm not sure how using sudo
this way would ever have worked. In any case, the better way to run shell code as root from AppleScript is to use with administrator privileges
instead of sudo
:
我不确定以这种方式使用sudo会有什么效果。在任何情况下,从AppleScript以超级用户身份运行外壳代码的更好方法是使用管理员权限而不是sudo:
do shell script "pmset -a disablesleep 0" with administrator privileges
tell application "System Events" to sleep
do shell script "pmset -a disablesleep 1" with administrator privileges
更多回答
do you know how to authorize this with touch?
你知道怎么用触摸来授权这个吗?
without touch, this won't function well enough for the larger application of this script.
如果没有接触,这将不能很好地用于此脚本的更大应用程序。
Do you have touch ID enabled for unlocking your Mac? I think that also controls whether it can work for this.
您是否启用了Touch ID来解锁Mac?我认为这也控制了它是否能对此起作用。
yes I have touch activated for the main unlocking. I think to get the old script to work, I added touch as sufficient for sudo in the pam.d folder. but I'm not sure what this new method would be under. or if it could be done the same way.
是的,我已经激活了主解锁的触控。我认为为了让旧脚本正常工作,我在pam.d文件夹中添加了足够用于sudo的Touch。但我不确定这种新方法会是什么样子。或者是否可以用同样的方式做到这一点。
我是一名优秀的程序员,十分优秀!