与对话窗口提示用户输入密码使用sudo时 [英] Prompt user for password with dialog window when using sudo

查看:546
本文介绍了与对话窗口提示用户输入密码使用sudo时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要执行一个命令使用sudo并希望显示一个对话框窗口,供用户输入其凭据。尝试定制与AppleScript的提示已经不折不扣的痛苦,并使用内置的做shell脚本以管理员权限不允许这样用户就知道如果请求是来自自定义窗口。

I need to execute a command with sudo and want to display a dialog window for the user to enter their credentials. Attempts to customize a prompt with Applescript have been nothing short of excruciating and using the built in "do shell script with with administrator privileges" doesn't allow for customizing the window so the user knows where the request is coming from.

当然,还有就是显示一个窗口的方式,让用户输入他们的凭据和发送的值回sudo来执行命令? <一href=\"http://www.performantdesign.com/2009/10/26/cocoasudo-a-graphical-cocoa-based-alternative-to-sudo/\"相对=nofollow> cocoasudo 看起来很有希望,但它也将在提示窗口,我需要用我的应用程序的名称,以取代写道:cocoasudo。有没有人找到一个解决方案实现这种功能?

Surely, there is a way to display a window, have the user enter their credentials and send the values back to sudo to execute the command? cocoasudo looks promising but it also writes "cocoasudo" in the prompt window which I need to replace with the name of my application. Has anyone found a solution for implementing this kind of functionality?

推荐答案

构建定制的窗户是超越了基本的AppleScript的范围。你需要,如果你想这个扩展您的编程技巧。你需要学习如何利用给苹果提供用于创建窗口和这样的工具。底线是,你需要去学习或者AppleScriptObjC或Objective-C /可可的API,以及如何在X code到使用它们。

Building custom windows is beyond the scope of basic applescript. You will need to expand your programming skills if you want this. You'll need to learn how to leverage to tools that Apple supplies for creating windows and such. Bottom line is you'll need to learn either AppleScriptObjC or Objective-C/Cocoa APIs and how to use them in Xcode.

随着中说,如果你不进入学习新东西,然后用你的工具。这样的事会工作。您可以自定义图标,按钮,文本等,你甚至可以有一个隐藏的答案输入密码时,保护用户。有很多你可以用AppleScript的做没有进一步学习...

With that said, if you're not into learning new stuff then use the tools you have. Something like this will work. You can customize the icon, the buttons, the text etc. you can even have a hidden answer to protect the user when entering passwords. There's lots you can do with Applescript without further learning...

display dialog "OSAScript will need an Admin User name and password in order to make your changes." & return & return & "Please enter an admin username." default answer "" with icon 2
set username to text returned of result

display dialog "OSAScript will need an Admin User name and password in order to make your changes." & return & return & "Please enter an admin password." default answer "" with icon 2 with hidden answer
set pssword to text returned of result

do shell script "osascript -e \"return 1\"" user name username password pssword with administrator privileges

这篇关于与对话窗口提示用户输入密码使用sudo时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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