如何读取AppleScript中的文件中的文本文件

时间:2014-05-02 01:13:50

标签: shell applescript

我如何阅读用户在pass.txt中定义的文本

这是我到目前为止测试它你必须在桌面上创建一个名为test

的文件夹

但是我打赌你们大多数人都可以想出来

set choice to the button returned of (display dialog "Login or Signup" buttons {"Quit", "Signup", "Login"} default button "Login")

if choice is "Signup" then

    set username to the text returned of (display dialog "Enter Desired Username" default answer "")

    do shell script "mkdir $HOME/Desktop/test/" & username
    do shell script "echo " & username & " > ~/desktop/test/" & username & "/username.txt"
    set pass to the text returned of (display dialog "Enter Password" default answer "")
    set input to pass
    do shell script "echo " & pass & " > ~/desktop/test/" & username & "/pass.txt"
else if choice is "Login" then


    set username to the text returned of (display dialog "Enter Username" default answer "")

    set y to username
    set z to "pass.txt"

    set x to "/Desktop/test/" & y


    words of {(read (POSIX file x) & "/pass.txt") as «class utf8»} contains pass -- true



    set pass to the text returned of (display dialog "Enter Password" default answer "")

else
    return 0
end if

1 个答案:

答案 0 :(得分:1)

括号未正确设置。试试这个:

read POSIX file (x & "/pass.txt")

do shell script "cat " & quoted form of (POSIX path of (path to desktop) & "test/" & username & "/pass.txt")

无论如何,脚本中还有许多其他问题。只是一些提示,使用......

- 引用形式的

- mkdir

的-p选项

- 密码输入的with hidden answer选项