Here is an AppleScript used in an Automator Application via the Run AppleScript action.
Launchpad : Other : Automator
- New : Application : Choose
- Utilities Library : Run AppleScript (drag and drop this to the right into larger workflow window).
- Select boiler plate contents and remove.
- Copy/paste contents of following AppleScript code into the Run AppleScript action window
Click the hammer icon
- Click the right-arrow (Run) icon in the top-right toolbar to run the Automator application interactively as a test
- Automator : File menu : Save... (you can name it copy_files, match_files, etc.) and put it on your Desktop.
Double-click to run
AppleScript code
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 folderwith promptmsg1default locationdefloc without invisibles, multiple selections allowed and showing package contents)
set outfolder to (choose folderwith promptmsg2default locationdefloc without invisibles, multiple selections allowed and showing package contents)
set name_file to (choose filewith promptmsg3default locationdefloc without invisibles, multiple selections allowed and showing package contents)
display dialoginfolder'sPOSIX path & return & outfolder'sPOSIX path & return & name_file'sPOSIX 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
duplicateanItemtooutfolder with replacing and exact copy
end repeat
end tell
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
Snapshot of Run AppleScript action with AppleScript code