简体   繁体   English

osascript和sudo密码输入

[英]osascript and sudo password entry

I am using osascript in a BASH script for dialog boxes on a MAC system. 我在BASH脚本的MAC系统上的对话框中使用osascript。 The problem I am having is several of the commands I need to use require privilages to function correct. 我遇到的问题是我需要使用的几个命令要求特权才能正常运行。 If I use sudo in the BASH script, the password prompt shows in the terminal window. 如果我在BASH脚本中使用sudo,则密码提示会显示在终端窗口中。 Is the some way I can hook the sudo password prompt into an osascript dialog box? 我可以通过某种方式将sudo密码提示挂接到osascript对话框中吗? Or is there a different way I can handle asking for the password in an osascript dialog box and passing it to some other program to handle it? 还是有其他方法可以处理我在osascript对话框中要求输入密码并将其传递给其他程序进行处理的方法?

What worked for me was to create the BASH script and then use osascript to call it. 对我有用的是创建BASH脚本,然后使用osascript对其进行调用。

$ osascript -e 'do shell script "/Path/yourbashscript.sh" with administrator privileges'

This will prompt a dialog box straight from Apple's infrastructure. 这将直接在Apple的基础结构中提示一个对话框。 Same one you see when you're asked for your username & password. 当询问您的用户名和密码时,您会看到相同的内容。

You can run this in terminal or use a third-party wrapper like, Platypus 您可以在终端中运行此程序,也可以使用像Platypus这样的第三方包装程序

You can suppress the password interface by modifying your Mac's authorization rights. 您可以通过修改Mac的授权权限来隐藏密码界面。

Use the built-in security command line tool or authbuddy to change the system.preferences.accessibility right to allow: 使用内置的安全命令行工具或authbuddy更改system.preferences.accessibility权限,以允许:

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. 打开system.preferences.accessibility权限将允许任何用户在没有密码提示的情况下更改可访问性设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM