Skip to content

Instantly share code, notes, and snippets.

@watershed
Created June 14, 2018 08:52
Show Gist options
  • Save watershed/7e7ad2dfeeb5022c4902bd2c3d181ec3 to your computer and use it in GitHub Desktop.
Save watershed/7e7ad2dfeeb5022c4902bd2c3d181ec3 to your computer and use it in GitHub Desktop.
Select files from list AppleScript
set myValues to {"filename.ext", "filename.ext"}
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
@watershed
Copy link
Author

watershed commented Jun 14, 2018

This is very inefficient and pounds the CPU. Much better off using something like the following in the command line:

cp ~/source/folder/{filename.ext,filename.ext} ~/destination/folder/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment