2013-11-21 146 views
1

我正在制作一个需要root权限的应用程序。我是新来的applscript和道歉,如果这是一个愚蠢的问题,但我想要做的是检查密码是否正确。我得到一个提示密码字符串是这样的:Applescript检查密码是否正确

set thePass to the text returned of (display dialog "I need you to enter your password" default answer "" buttons {"Okay"} default button 1 with icon file ((path to resource "Icon.icns") as text) with hidden answer) 

我需要检查是否thePass实际上是在继续之前他们的密码。我不想仅使用默认密码提示。有没有办法做到这一点?

我已经尝试了一下,在错误语句中测试密码时,如果输入的密码不正确,它只会提示输入密码。

回答

2

好这里是如何我只是解决了它: 1)获取一个变量

2)尽量使用sudo来运行一个命令(使用标准输入为输入)的密码,这将失败,如果密码是不正确

try 
    do shell script "echo '" & thePass & "' | sudo -S :" 
onerror 
    display alert "Incorrect Password!" 
end try 
1

不知道你想要做什么,但如果你想使用sudo来执行shell脚本,你应该做

do shell script shellScriptVariable with administrator privileges 

没有“命令”中的shell脚本。如果密码错误,您将自动获得错误对话框。