我在 MAC 系统上的对话框的 BASH 脚本中使用 osascript。我遇到的问题是我需要使用的几个命令需要特权才能正常运行。如果我在 BASH 脚本中使用 sudo,密码提示将显示在终端窗口中。我可以通过某种方式将 sudo 密码提示挂接到 osascript 对话框中吗?或者有什么不同的方法可以处理在 osascript 对话框中询问密码并将其传递给其他程序来处理它?
问问题
1709 次
2 回答
3
对我有用的是创建 BASH 脚本,然后使用 osascript 调用它。
$ osascript -e 'do shell script "/Path/yourbashscript.sh" with administrator privileges'
这将直接从 Apple 的基础架构提示一个对话框。当您被要求输入用户名和密码时,您会看到相同的内容。
您可以在终端中运行它或使用第三方包装器,如鸭嘴兽
于 2015-11-06T06:13:06.127 回答
0
You can suppress the password interface by modifying your Mac's authorization rights.
Use the built-in security command line tool or authbuddy to change the system.preferences.accessibility right to allow:
sudo security authorizationdb write system.preferences.accessibility allow
Opening up the system.preferences.accessibility right will permit any user to change the accessibility settings without a password prompt.
于 2015-02-26T21:02:30.263 回答