我对Applescript还不熟悉。我很难理解如何读取和写入文本文件并将内容用作变量。我已经对此做过研究,但没有什么是可行的,也没有任何意义。我想读取一个文本文件,其中包含一个或多个单词。单词或数字,比方说123,将分配给一个名为pass的变量。我需要一个Applescript来询问用户密码应该是什么,然后创建一个包含密码的新文本文件。我还需要一个Applescript来更改密码。下面的Applescript将用于更改密码。
set theFile to "Users:username:Desktop:pass.txt" as alias
set pass to (read file theFile)
display dialog "Password:" default answer "" with hidden answer
if text returned of result is pass then
display dialog "New Password:" default answer "" with hidden answer
display dialog "Again:" default answer "" with hidden answer
-- code here to change text in pass.txt
display dialog "Password changed."
end if我只是需要一个初学者,或一个有用的网站,或任何可以帮助我。谢谢!
发布于 2015-01-29 08:09:57
您可以使用普通的Applescript 标准添加器来完成这一任务。您可以在文件读/写部分中找到处理程序。
set theFile to "Users:Username:Desktop:pass.txt" as alias
set pass to (read theFile)
display dialog "Password:" default answer "" with hidden answer
if text returned of result is pass then
set newPass1 to text returned of (display dialog "New Password:" default answer "" with hidden answer)
set newPass2 to text returned of (display dialog "Again:" default answer "" with hidden answer)
-- check the new passwords
if newPass1 = newPass2 and newPass1 ≠ "" then
-- open the file
set pwdFile to open for access theFile with write permission
-- delete the content
set eof of pwdFile to 0
-- write new content
write newPass1 to pwdFile
-- close the file
close access pwdFile
display dialog "Password changed."
end if
end if顺便说一句:read theFile不需要文件,您的别名theFile就足够了!
顺便说一句:我希望这个剧本只是为了学习。我强烈建议不要这样处理用户的密码.!
享受,迈克尔/汉堡
https://stackoverflow.com/questions/28209265
复制相似问题