Need help with AppleScript for searching CSV file for matches to copy

Joined
Jul 25, 2016
Messages
2
Reaction score
0
Points
1
Hi,

I am totally useless scripting, so i hope you can help. I got this script from macscripter.com and i can not get the **** thing to work, seems to only pick up the first filename in the CSV and leave the rest, what is missing?

I have 300 files to match and this will save me a whole bunch of a head ache. please help.

I am using EL Captain, maybe there is something that has in AppleScript in this version?


Code:
--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 files 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 Source_Folder_full_list)
		set file_source_One to item i of Source_Folder_full_list
		set file_source_OneName to name of file_source_One
		
		if (file_source_OneName is in Source_List) then
			duplicate file_source_One to Target_Folder with replacing
		end if
		
	end repeat
	beep 1
	display dialog "All files were duplicated as requested." giving up after 3
	
end tell



so if a CSV has the below

fileX2.png
fileY2.png


the script seems to only pick the first CSV value fileX2.png even though the other fileY2.png is in the folder.
 
Last edited:
Joined
Apr 16, 2016
Messages
1,096
Reaction score
51
Points
48
Location
CT
Your Mac's Specs
MacBook Air Mid-2012 / iMac Retina 5K Late-2014
First, welcome.

Second, language, please. No need to be swearing in your very first post (or any post, for that matter).

Third, you're not likely to get a solid answer to your query since you didn't post your specific need. It's great that you found a script that you -believe- does what you need, but it's more important to explain the scenario to us instead of asking us to debug a script that we don't understand whether it will provide what you need or not.

Fourth, attend to detail. When it comes to scripting, you have to be meticulous and precise. While, as humans, we understand that you meant "El Capitan" when you wrote "El Captain", scripts and computer programs take you literally.
 
OP
A
Joined
Jul 25, 2016
Messages
2
Reaction score
0
Points
1
First, welcome.

Second, language, please. No need to be swearing in your very first post (or any post, for that matter).

Third, you're not likely to get a solid answer to your query since you didn't post your specific need. It's great that you found a script that you -believe- does what you need, but it's more important to explain the scenario to us instead of asking us to debug a script that we don't understand whether it will provide what you need or not.

Fourth, attend to detail. When it comes to scripting, you have to be meticulous and precise. While, as humans, we understand that you meant "El Capitan" when you wrote "El Captain", scripts and computer programs take you literally.


No problem, I resolved the matter anyways, paid someone to do this for me. Much simpler and quicker to achieve what i needed. Thanks anyways.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top