Applescript: Copy files from a folder that contains jpegs using txt files that contains unique codes
I found this very helpful thread:
Automator/Applescript: Copy Files to Fold… - Apple Community
This really helped me! But my situation is a bit different.
My list only contains the unique codes.
So I need to copy all the files that contains the list of unique codes on their filenames.
This is the code that I am using: (I got from the mentioned thread)
---------------------------------------------------------------------------------------------------------------
property defloc : (path to desktop as text) as alias
property msg1 : "Select the input folder"
property msg2 : "Select the output folder"
property msg3 : "Select the input file with filenames"
use scripting additions
set name_list to {}
set match_list to {}
try
set infolder to (choose folder default location defloc with promptmsg1 without invisibles, multiple selections allowed and showing package contents)
set outfolder to (choose folder default location defloc with promptmsg2 without invisibles, multiple selections allowed and showing package contents)
set name_file to (choose file default location defloc with promptmsg3 without invisibles, multiple selections allowed and showing package contents)
display dialog infolder's POSIX path & return & outfolder's POSIX path & return & name_file's POSIX path
-- read names from file into quoted filename list
set name_list to read name_file as «class utf8» using delimiter linefeed
with timeout of 1800 seconds
tell application "Finder"
-- get every filename in infolder hierarchy whose filename matches names in name list
set match_list to (every item of entire contents of folder infolder whose name is in name_list) as alias list
-- copy the files to outfolder with exact permissions and overwrite if required
repeat with anItem in match_list
duplicate anItem to outfolder with replacing and exact copy
end repeat
end tell
end timeout
on error errmsgnumbererrnbr
my error_handler(errnbr, errmsg)
end try
return
on error_handler(nbr, msg)
return display alert "[ " & nbr & " ] " & msg as critical giving up after 10
end error_handler
---------------------------------------------------------------------------------------------------------------
My list contains only the unique codes: (screenshot below)
But from the folder where I want my script to copy some files contains variants of the unique codes from my list.
I hope someone could help me. Thanks!