osascript和sudo密码输入 [英] osascript and sudo password entry

查看:329
本文介绍了osascript和sudo密码输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在BASH脚本中的osascript中使用了MAC系统上的对话框.我遇到的问题是我需要使用的几个命令要求特权才能正常运行.如果我在BASH脚本中使用sudo,则密码提示会显示在终端窗口中.我可以通过某种方式将sudo密码提示挂接到osascript对话框中吗?还是有其他方法可以处理我在osascript对话框中要求输入密码并将其传递给其他程序进行处理的方法?

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?

推荐答案

对我有用的是创建BASH脚本,然后使用osascript进行调用.

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'

这将提示一个直接来自Apple基础设施的对话框.询问您的用户名&时,您会看到同一个人密码.

This will prompt a dialog box straight from Apple's infrastructure. Same one you see when you're asked for your username & password.

您可以在终端中运行此程序,也可以使用 Platypus

You can run this in terminal or use a third-party wrapper like, Platypus

这篇关于osascript和sudo密码输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆