Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File Applescript选择其名称包含值或文本列表任何部分的文件_File_Select_Applescript - Fatal编程技术网

File Applescript选择其名称包含值或文本列表任何部分的文件

File Applescript选择其名称包含值或文本列表任何部分的文件,file,select,applescript,File,Select,Applescript,我需要从文件夹中选择一组具有不同名称的文件。这是我到目前为止必须在小规模上完成的脚本 tell application "Finder" to select (every file of target of front window whose name contains "3123" or name contains "3125" or name contains 3166) 但我需要一个大规模工作的脚本,在这里我可以输入类似于 set myValues to {3101, 3102, 3

我需要从文件夹中选择一组具有不同名称的文件。这是我到目前为止必须在小规模上完成的脚本

tell application "Finder" to select (every file of target of front window whose 
name contains "3123" or name contains "3125" or name contains 3166)
但我需要一个大规模工作的脚本,在这里我可以输入类似于

set myValues to {3101, 3102, 3103, 3456, 6789, etc. etc.}
tell application "Finder" to select (every file of target of front window whose 
name contains myValues)
但当我使用该脚本时,当我将多个数字设置为myValues时,它不会选择任何文件。另外,如果你能告诉我如何改变它与文本以及工作,这将是可怕的

谢谢你的帮助

试试看:

set myValues to {"3101", "3102", "3103", "3456", "6789"}

tell application "Finder" to set fileList to files of target of front window

set matchedFiles to {}
repeat with aFile in my fileList
    repeat with aValue in myValues
        tell application "System Events" to if aFile's name contains (contents of aValue) then set end of matchedFiles to (aFile as text)
    end repeat
end repeat

tell application "Finder" to select matchedFiles
编辑-添加查找窗口和regulus6633的建议:

set myValues to {"3101", "3102", "3103", "3456", "6789"}

tell application "Finder" to set fileList to files of target of front Finder window as alias list

set matchedFiles to {}
repeat with aFile in my fileList
    repeat with aValue in myValues
        tell application "System Events" to if aFile's name contains (contents of aValue) then set end of matchedFiles to (aFile as text)
    end repeat
end repeat

tell application "Finder" to select matchedFiles
编辑2

set myValues to {"3125", "3123"}

tell application "Finder" to set fileList to files of target of front Finder window as alias list
set matchedFiles to {}
repeat with aFile in my fileList
    repeat with aValue in myValues
        tell application "System Events" to if aFile's name contains (contents of aValue) then set end of matchedFiles to (aFile as text)
    end repeat
end repeat

if matchedFiles ≠ {} then
    tell application "Finder"
        select matchedFiles -- you don't need to select files to duplicate them
        duplicate matchedFiles to (choose folder)
    end tell
end if

在没有任何测试的情况下,我的问题是系统事件是否可以处理Finder文件说明符。如果是这样,那么没有问题,否则您可以在第一个Finder命令的末尾追加“as alias list”。一开始我认为这会是一个问题,但我不确定。它似乎对我有效,但你是对的,你可以在顶部创建一个别名列表,以避免任何查找器/系统事件引用问题。工作起来像一个champ!你们都很棒。我有苹果培训系列:Applescript 1-2-3今天到达。所以希望我能从中回答我未来的问题。再次感谢!所以,我试图将这些选定的文件传递到Automator中的操作中,但这并没有按计划进行。我读了一些Applescript 1-2-3的书,试图将这些选定的文件复制到我选择的新文件夹中。但在尝试了一百万种不同的组合后,我还是无法解决这个问题。下面是我的脚本将myValues设置为{“3125”,“3123”}告诉应用程序“Finder”将fileList设置为front Finder窗口目标的文件,就像别名列表将matchedFiles设置为{}在我的fileList中用文件重复使用aValue在myValues告诉应用程序一样“系统事件”设置为如果文件名包含(aValue的内容),则将matchedFiles的结尾设置为(文件为文本)end repeat end repeat告诉应用程序“Finder”选择matchedFiles duplicate matchedFiles以选择文件夹