0

フォルダから名前の異なる一連のファイルを選択する必要があります。これは、これまで小規模で作業しなければならなかったスクリプトです。

tell application "Finder" to select (every file of target of front window whose 
name contains "3123" or name contains "3125" or name contains 3166)

しかし、次のような myValues を入力するだけで大​​規模に機能するスクリプトが必要です

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 に複数の数値が設定されていると、ファイルが選択されません。また、テキストでも機能するように変更する方法を教えていただければ、それは素晴らしいことです。

助けてくれてありがとう!

4

1 に答える 1

2

試す:

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

編集 - Finder ウィンドウと 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
于 2013-06-11T14:35:47.833 に答える