我有一个输出文件名的shell脚本(每行一个)。我想将该输出放入AppleScript的列表中。
我该怎么做?
如何将这些文件名字符串转换为文件对象的加分点。
编辑:
尝试时:
set theFiles to {}
repeat with i from 1 to count of filenames
set end of theFiles to (POSIX file (item i of filenames))
end repeat
我明白了:
error "Finder got an error: Can’t get POSIX file \"/path/to/file\"." number -1728 from file "Macintosh HD:path:to:file"
EDIT-2:
结果发现查找器不知道在“tell”语句启动后创建的文件。如何更新它或让它知道新文件?
EDIT-3:
这有用(注意添加“我的”):
set theFiles to {}
repeat with i from 1 to count of filenames
set end of theFiles to (my POSIX file (item i of filenames))
end repeat
答案 0 :(得分:2)
set myFilenamesList to paragraphs of (do shell script "path/to/shell/script")
set firstFileObject to POSIX File (item 1 of myFilenamesList)
如果有列表,则使用重复循环迭代列表并对列表中的项执行某些操作。例如,如果你想要一个文件对象列表,你可以这样做。
set fileObjectsList to {}
repeat with i from 1 to count of myFilenamesList
set end of fileObjectsList to POSIX File (item i of myFilenamesList)
end
return fileObjectsList
当然这样做没有多大意义,因为一旦你有一个列表中的文件对象,你就需要重复该列表来对这些对象做一些事情...因此你会重复超过列表2次,一次可能就足够了。所以我会做这样的事情......
repeat with i from 1 to count of myFilenamesList
set thisFileObject to POSIX File (item i of myFilenamesList)
-- do something with the file object "thisFileObject"
end