Automator/Applescript: Copy Files to Folder from a list (text file)
Hi all. I have a folder of files, and a list (text file) of ones I need from that folder. I'm trying to make an Automator application that will read the list, find the files, and copy them to a new folder. I found this previous post (https://discussions.apple.com/thread/7928846) and tried both the method in that post as well as the method referenced in the first link. In both cases, Finder times out before it finds and copies any files, and then it has to be relaunched. I've tested with just one name in the text file, which I've confirmed is in the folder, and it still won't work. I've posted the AppleScript I'm using below. Any suggestions?
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 with prompt msg1 default location defloc without invisibles, multiple selections allowed and showing package contents)
set outfolder to (choose folder with prompt msg2 default location defloc without invisibles, multiple selections allowed and showing package contents)
set name_file to (choose file with prompt msg3 default location defloc 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
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
on error err msgnumber errnbr
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