Hello, folks.
Newbie scripter here. Please be patient with me.
I am tasked with writing an Applescript which can do the following things:
- Ask user to point to a previously-built CSV file containing only exact filenames of desired files.
- Ask user to define a folder in which said named files reside. (āSource Folderā)
- Ask user to define a desired folder into which said files will be duplicated. (āTarget Folderā)
- Duplicate all files in the CSV list to the Target Folder, even if those files might be in a subfolder of the Source Folder.
Number 4 is key here, as the user is NOT expected to know where the files actually reside. They should be able to point to an entire yearās worth of job folders containing a myriad of subfolders and still be able to pull their list.
THE THING ISā¦
I have a script all written that can do everything EXCEPT #4, which totally kills the functionality of the script.
As written, the script fails when I point to the parent folder of the folder where my sample files live.
I get the error:
Canāt make item 5 of alias āORC Studio:Job Work:ORC FTP workfiles:ORC Studio GPS:ā into type alias.
When the list of items is returned, I can see that the first item is an InDesign document, followed by three folders (items 2,3 & 4). Item 5 is a Photoshop file, and is the first on the list AFTER the script found some folders.
The line which reports the error is this one:
set file_source_OneNameAlias to (item i of Source_Folder) as alias
Here is the script.
Can anyone assist?
--Sur la Table script for copying files to a new location using a CSV file as source.
--This script assumes the following:
-- The CSV file contains no empty cells and no erroneous filenames
-- The files indicated in the CSV file are actually located in the SOURCE folder
tell application "Finder"
activate
--CODE for getting the INFO from a file
set CSV_source_File to choose file with prompt "Select the CSV file containing the filenames you need to find and duplicate." without invisibles
set OldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {return} --this MUST be return when using CSV files
--CODE telling the script to make a list from the selected file.
set Source_List to every text item of ((read CSV_source_File) as string)
set AppleScript's text item delimiters to OldDelims
--CODE for choosing your SOURCE:
set Source_Folder to choose folder with prompt "Choose SOURCE FOLDER of files." & return & "(Files here that match the filenames in your CSV file" & return & "will be duplicated to a new TARGET location.)" without invisibles
--display dialog "You have chosen SOURCE FOLDER:" & return & Source_Folder -- this is just feedback and can be deleted
set Source_Folder_full_list to name of entire contents of Source_Folder
--CODE for choosing your TARGET:
set Target_Folder to choose folder with prompt "Choose a TARGET FOLDER to duplicate the SOURCE files to." & return & return & "The count of files to be duplicated is " & return & (count of Source_List) & return & "Please check the folder when done." without invisibles
--display dialog "You have chosen TARGET FOLDER:" & return & Target_Folder -- this is just feedback and can be deleted
--Here's the meat of it:
repeat with i from 1 to count of items in Source_Folder_full_list
if (i as string) does not end with ":" or (aItem as string) does not start with "." then --check for folders and invisibles (want to ignore those)
set file_source_OneNameAlias to (item i of Source_Folder) as alias
set file_source_OneName to (item i of Source_Folder_full_list)
--set Source_Folder_full_list to Source_Folder_full_list as string
repeat with i from 1 to count of items in Source_List
if file_source_OneName = item i of Source_List then
duplicate file file_source_OneNameAlias to Target_Folder with replacing
display dialog "The file " & return & return & file_source_OneName & return & return & "was duplicated." giving up after 1
exit repeat
end if
end repeat
end if
end repeat
beep 1
display dialog "All files were duplicated as requested." giving up after 3
end tell