【发布时间】:2015-04-21 22:42:00
【问题描述】:
我一直在尝试拼凑一个脚本以从文本文档中获取文件列表,并让 applescript 逐行遍历列表,然后对文件执行某些操作。在这种情况下,它正在更改文件上的标签,但我们会在其他情况下使用它来移动文件等。
它适用于我桌面上的测试文件,这些文件标有紫色标签,但是当我尝试在我实际需要的文件夹中运行它时,它会失败并显示以下错误消息:
error "Finder 出错:无法将 1 设置为 5。"从 1 开始的数字 -10006
除了内容长度之外,文本文件是相同的。
这可能是文件名的问题吗?如果是,我该如何让脚本更宽容。
这是脚本:
set textFileContents to POSIX path of (choose file)
set dataList to paragraphs of (read textFileContents as «class utf8»)
tell application "System Events"
repeat with thisFileName in dataList
tell application "Finder" to set (label index of files whose name is thisFileName) to 5
end repeat
end tell
任何帮助将不胜感激,谢谢。
1080074 3.tif
1080074 2.tif
1080069_A1.tif
这是解决此问题的最终代码以及我所做的一些进一步工作。
感谢@Mark Setchell 和@jackjr300 的耐心帮助。
set justpath to POSIX path of (choose folder with prompt "Select the Folder with Files You Want to Use")
set textFileContents to (choose file with prompt "Select the list of files")
set dataList to paragraphs of (read textFileContents as «class utf8»)
tell application "Finder"
repeat with FileName in dataList
try -- need a try block to ignore error, in case that the file has been moved or deleted
set label index of (justpath & FileName as POSIX file as alias) to 5
end try
end repeat
end tell
【问题讨论】:
标签: automation applescript text-files