Applescript:文本编辑密码
Applescript: Textedit Password
我是 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
我只需要一个启动器、一个有用的网站或任何可以帮助我的东西。谢谢!
您可以使用普通的 Applescript 标准添加 来做到这一点。您可以在 File Read/Write 部分中找到处理程序。
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 就足够了!
顺便说一句:我希望这个脚本仅用于学习目的。我强烈建议不要以这种方式处理您的用户密码...!
享受吧,迈克尔/汉堡
我是 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
我只需要一个启动器、一个有用的网站或任何可以帮助我的东西。谢谢!
您可以使用普通的 Applescript 标准添加 来做到这一点。您可以在 File Read/Write 部分中找到处理程序。
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 就足够了!
顺便说一句:我希望这个脚本仅用于学习目的。我强烈建议不要以这种方式处理您的用户密码...!
享受吧,迈克尔/汉堡