如何使用applescript中的tell函数返回的数据?

如何使用applescript中的tell函数返回的数据?,applescript,Applescript,我对applescript很陌生,但我想我已经了解了它的要点。我试图写一些东西来启用/禁用从睡眠中醒来时需要密码的功能,但我需要做的是获取它返回的值,并将其设置为一个变量,以便以后查看 tell application "System Events" to set security preferences's require password to wake to not (security preferences's require password to wake) 在结果中,会显示tru

我对applescript很陌生,但我想我已经了解了它的要点。我试图写一些东西来启用/禁用从睡眠中醒来时需要密码的功能,但我需要做的是获取它返回的值,并将其设置为一个变量,以便以后查看

tell application "System Events" to set security preferences's require password to wake to not (security preferences's require password to wake)
在结果中,会显示true或false,这就是我希望在对话框中显示的内容,尽管我将重写它。然而,我不知道如何计算结果的值。问题是,因为唤醒所需的密码在tell中,所以我不知道如何检索它的布尔值

我的整个剧本就是这样。我知道这可能很混乱,但这几乎是我第一次体验applescript

tell application "System Events" to set security preferences's require password to wake to not (security preferences's require password to wake)
tell application "System Events" to return security preferences's require password to wake as boolean
tell application "System Events" to return security preferences's require password to wake as boolean
if the "require password to wake" is false then display dialog (password_req as boolean)
if the "require password to wake" is false then display dialog (password_req as boolean)
if boolean = true then display dialog (boolean as text)
if boolean = false then display dialog (boolean as text)
get "require password to wake" as text
display dialog "require password to wake"
beep
display alert "Password toggled."
return

更进一步的基本解释:块不是函数,函数在AppleScript中称为处理程序。tell块将特定的apple事件发送到适当的进程/应用程序,或发送到窗口、单词等对象。。要从处理程序返回,请将要返回的内容放在处理程序的最末端。这里有很好的学习材料:
tell application "System Events"
 --note that this is a 'true tell block' as opposed to a one-liner
 set security preferences's require password to wake to not (security preferences's require password to wake)
 --above line can't return result. to do that you do:
 set passReq to security preferences's require password to wake
end tell--block end

--ok, you've toggled it. now report it:

display dialog ("Password required is set to " & (passReq as text))