我最近在开发一个AppleScript项目,需要将用户的密码复制到剪贴板供以后使用。我已经有提示用户输入密码的部分,但如何将返回的文本(他们的密码)设置到剪贴板。我当前的代码给了我错误:Can’t make text returned of «script» into type text.
这是我到目前为止所做的:
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
答案 0 :(得分:0)
通过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