Applescript,读取行作为变量

use*_*814 2 applescript text

我希望Applescript能够从txt文件中设置变量,逐行读取或逐个字符地读取.也许像php函数:get_file_contents.有没有类似的东西或者你可以请我提供方式吗?

我知道如何设置文件路径.就像是

    set myfile to "/Users/Username/Desktop/test.txt"
    set theText to read myfile
Run Code Online (Sandbox Code Playgroud)

在txt文件中,它只是一行中的一个整数,比如

    1
    2
    3
    4
    5
Run Code Online (Sandbox Code Playgroud)

如果我使用

    set theTextList to paragraphs of theText
Run Code Online (Sandbox Code Playgroud)

结果将带有引号"".

我只想将这些整数设置为变量.所以以后我可以使用,比如

   set variable to 5  --here I would like to replace the real number 5 to the number I read from the txt file(just one line)

   start slideshow
   show slide variable
Run Code Online (Sandbox Code Playgroud)

在此先感谢您的帮助.

Mic*_*ich 5

如果文件的行由返回字符分隔,这样的东西应该工作:

set allRecords to read myfile using delimiter return
repeat with aRecord in allRecords
    if length of aRecord is greater than 0 then
        set variable to aRecord
        log "variable: " & variable
    end if
end repeat
Run Code Online (Sandbox Code Playgroud)

如果您的文件与return不同,则可以更改代码第一行中的分隔符.