我希望 Applescript 从 txt 文件设置变量,逐行或逐字符读取。也许像 php 函数:get_file_contents。有没有类似的或者可以给我提供一下方法吗?
我知道如何设置文件路径。就像
set myfile to "/Users/Username/Desktop/test.txt"
set theText to read myfile
在txt文件中,它只是一行中的一个整数,例如
1
2
3
4
5
如果我使用
set theTextList to paragraphs of theText
结果将带有引号“”。
我只想将这些整数设置为一个变量。这样以后我就可以使用,比如
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
预先感谢您的帮助。
最佳答案
如果文件的行由返回字符分隔,则应该可以使用以下内容:
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
如果文件中的字符与 return 不同,您可以更改代码第一行中的分隔字符。
关于text - Applescript,将行读取为变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16044127/