【问题标题】:Applescript: Textedit PasswordApplescript:文本编辑密码
【发布时间】:2015-01-29 07:36:08
【问题描述】:

我是 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

我只需要一个入门者、一个有用的网站或任何可以帮助我的东西。谢谢!

【问题讨论】:

    标签: macos passwords applescript textedit


    【解决方案1】:

    您可以使用普通的 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
    

    BTW:read theFile 不需要文件,你的别名 theFile 就够了!

    顺便说一句:我希望这个脚本仅用于学习目的。我强烈建议不要以这种方式处理您的用户密码...!

    享受吧,迈克尔/汉堡

    【讨论】:

    • 谢谢!这正是我所需要的。
    猜你喜欢
    • 2014-03-20
    • 1970-01-01
    • 2021-05-01
    • 1970-01-01
    • 2018-04-07
    • 1970-01-01
    • 2011-03-15
    • 1970-01-01
    • 2014-02-07
    相关资源
    最近更新 更多