使用applescript移动名称出现在Excel电子表格中的文件

我有一个包含大约4000个图像文件的文件夹。 我需要根据他们的名字是否出现在Excel电子表格中来select其中的一些文件,并将它们复制到一个新的文件夹中。 如果可能的话,我也想用一个颜色标签来标记它们,这样我就知道原始文件夹中的哪些文件被移动了,哪些不是。 我从这里得到了下面的代码。

tell application "Microsoft Excel" tell worksheet 1 of active workbook set fileList to value of used range end tell end tell set rootFolder to "path/to/sourcefolder" as POSIX file set filesToMove to {} repeat with thisItem in fileList try set end of filesToMove to alias (rootFolder & thisItem) on error display dialog "File " & thisItem & " is not in the folder" end try end repeat tell application "Finder" move filesToMove to folder "path/to/destination" as POSIX file end tell 

当我运行它时,无法find任何文件。 我认为这个问题可能与使用/在我的文件path,而不是:但我不知道如何设置一个外部驱动器与苹果脚本语法的path。 使用相同的variables声明, set rootFolder to "path/to/sourcefolder" as POSIX file ,然后告诉finder open rootFolder工作正常。

我还需要脚本具有更大的灵活性 – 并非所有文件都具有相同的命名约定,因此我需要它search名称中包含电子表格中标识符的任何文件,但可能不完全匹配它。 IE的电子表格条目可能是“00103”,但文件名是“PX00103KL.jpg”。

同时,我创build了一个自动化工作stream程,可以按照我想要的方式移动和标记文件,但只能在手动inputsearchstring之后进行。 如果我可以结合这两个想法,通过Excel中的电子表格条目进行迭代,并依次使用它们作为自动工作stream程的input,那么这将是理想的。

谢谢你的帮助!

我没有Excel,但假设你可以从中得到一个string列表,下面是一些代码,它将查找目标文件夹中包含string的所有文件,为它设置一个标签,然后复制它。 适当地改变。

它使用unix命令行工具聚焦, mdlist来查找文件。 试图纯粹在applescript中这似乎是痛苦的。 在缝合在一起的shell命令是这样的:

mdfind -onlyin ~/Documents/ "kMDItemDisplayName == '*somestring*'"

这里是代码:

 set stringList to {"144", "g_"} set rootFolder to "/Users/blah/Downloads/" as POSIX file set destFolder to "/Users/blah/Downloads/test" as POSIX file set filesToMove to {} set mdAtr to "\"kMDItemDisplayName == '*" repeat with thisItem in stringList set sPath to quoted form of POSIX path of rootFolder set sName to mdAtr & thisItem & "*'\"" set sCmd to "mdfind -onlyin " & sPath & " " & sName set sResults to (do shell script sCmd) set fList to (every paragraph of sResults) as list repeat with i in fList set f to (POSIX file i) as alias tell application "Finder" set label index of f to 3 #copy file f to folder (destFolder as alias) end tell end repeat end repeat