osascript and sudo password entry

断了今生、忘了曾经 提交于 2019-12-12 04:56:36

问题


I am using osascript in a BASH script for dialog boxes on a MAC system. 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. Is the some way I can hook the sudo password prompt into an osascript dialog box? 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?


回答1:


What worked for me was to create the BASH script and then use osascript to call it.

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

This will prompt a dialog box straight from Apple's infrastructure. 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




回答2:


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.



来源:https://stackoverflow.com/questions/28752365/osascript-and-sudo-password-entry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!