Passwords 如何将剪贴板设置为AppleScript上返回的文本

Passwords 如何将剪贴板设置为AppleScript上返回的文本,passwords,applescript,clipboard,Passwords,Applescript,Clipboard,我最近正在做一个AppleScript项目,该项目要求将用户的密码复制到剪贴板,以便以后使用。我已经有了提示用户输入密码的部分,但是如何将返回的文本(他们的密码)设置到剪贴板。我当前的代码给了我一个错误:无法将«script»返回的文本转换为文本类型。这就是我目前的情况: set usr to short user name of (system info) repeat display dialog "Please enter login password to continue:"

我最近正在做一个AppleScript项目,该项目要求将用户的密码复制到剪贴板,以便以后使用。我已经有了提示用户输入密码的部分,但是如何将返回的文本(他们的密码)设置到剪贴板。我当前的代码给了我一个错误:
无法将«script»返回的文本转换为文本类型。
这就是我目前的情况:

set usr to short user name of (system info)
repeat
    display dialog "Please enter login password to continue:" default answer "" buttons {"Submit"} with title "Enter password" with icon stop with hidden answer
    set pswd to text returned of the result
    try
        do shell script "echo test" user name usr password pswd with administrator privileges
        exit repeat
    end try
end repeat
set a to (text returned) as list
set AppleScript's text item delimiters to linefeed
set a to a as text
set the clipboard to a

当通过
do shell script
运行shell脚本时,我通常在applescript中使用一个变量来捕获结果。我不确定是否有一个“正确”的方法来做到这一点,但我删除了你的脚本

set a to (text returned) as list  
set AppleScript's text item delimiters to linefeed  
set a to a as text  
并将
do shell script
命令的结果捕获为变量
a
,然后将其放在剪贴板上。以下是修改后的脚本:

set usr to short user name of (system info)
repeat
    display dialog "Please enter login password to continue:" default answer "" buttons {"Submit"} with title "Enter password" with icon stop with hidden answer
    set pswd to text returned of the result
    try
        set a to do shell script "echo test" user name usr password pswd with administrator privileges
        exit repeat
        end try
end repeat
set the clipboard to a
如果您想进一步精简它,可以完全消除变量
a
,并将
do shell script
命令的结果直接捕获到剪贴板:

set usr to short user name of (system info)
repeat
display dialog "Please enter login password to continue:" default answer "" buttons {"Submit"} with title "Enter password" with icon stop with hidden answer
set pswd to text returned of the result
try
    set the clipboard to (do shell script "echo test" user name usr password pswd with administrator privileges)
    exit repeat
end try
end repeat