gpt4 book ai didi

file - 将文本文件读入 Applescript 中的列表

转载 作者:行者123 更新时间:2023-12-04 17:38:39 25 4
gpt4 key购买 nike

我试图创建一个 AppleScript,它读取一个文本文件并将内容放入一个列表中。该文件是一个简单的文本文件,其中每一行如下所示:example-"example"
第一个是文件名,另一个是文件夹名。

这是我现在的代码:

set listOfShows to {}
set theFile to readFile("/Users/anders/Desktop/test.txt")
set Shows to read theFile using delimiter return
repeat with nextLine in Shows
if length of nextLine is greater than 0 then
copy nextLine to the end of listOfShows
end if
end repeat
choose from list listOfShows


on readFile(unixPath)
set foo to (open for access (POSIX file unixPath))
set txt to (read foo for (get eof foo))
close access foo
return txt
end readFile

当我运行输出时,我得到了这个:
error "Can not change \"Game.of.Thrones-\\\"Game Of \" to type file." number -1700 from "Game.of.Thrones-\"Game Of " to file"

我的列表看起来像这样:Game.of.Thrones-“权力的游戏”和另外两行这样的。

最佳答案

错误是您试图将文件(您读取的第一个文件)的内容作为文件读取。获取 段落文本将在回车/换行边界处将其分开,这通常比尝试猜测文件中使用的行尾字符更好。

你也不需要整个 开放访问 只是读取文件时的事情,所以你的脚本可以减少到只是

set listOfShows to {}
set Shows to paragraphs of (read POSIX file "/Users/anders/Desktop/test.txt")
repeat with nextLine in Shows
if length of nextLine is greater than 0 then
copy nextLine to the end of listOfShows
end if
end repeat
choose from list listOfShows

关于file - 将文本文件读入 Applescript 中的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10064849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com