The problem should be dead simple for someone knowing Applescript; alas I am a total noob.
This is going to be a long post, so please be so kind to bear with me. It is just to provide a clear description of the problem at hand.
I shoot gymnastics sessions from time to time. More than 200 athletes take part. Photographs in each shooting can be anything from 600-1000.
Each athlete orders a number of photos that I print and then mail away to them. In each shooting, every photo shot has a unique number as a filename: 1.jpg, 2.jpg… 600.jpg.
All athletes are given also a unique id (1, 2, 3, 4) etc.
What I need to do is have a CSV file where each line contains as the first component the id of the athlete and then the photos ordered, like:
1; 50; 50; 128; 220
2; 140; 195; 210
3; 10; 10; 10
So, in the example above, Athlete with ID 1 has ordered two prints of photograph 50.jpg, and single prints of photos 128 and 220.
The script I am trying to create reads this CSV file, records the customer id and then the photos ordered and then copies the photos ordered to another common folder RENAMING the photo, according to a simple rule: (number).jpg → (cust ID)-(number)[-(seq)].jpg. As an example, again for athlete with ID 1 photos 50, 128 and 220 will be copied with the following names:
1-50.jpg
1-50-2.jpg
1-128.jpg
1-220.jpg
This way it becomes really easy to sort out the actual prints and put them in envelopes for each athlete (the filename is printed in the flip side of the photo, making identification possible).
Based on nice examples I found here I started the script below:
property photos : {}
tell application “TextEdit”
set sourceFile to (“Users:etsiot:Documents:photocopies.csv”)
set pixinfo to read file sourceFile
set entries to paragraphs of pixinfo
set {myTID, AppleScript’s text item delimiters} to {AppleScript’s text item delimiters, {“;”}}
set j to 0
repeat with i from 1 to count entries
set lineitems to words of (item i of entries)
set linewords to text items of lineitems
set allwords to (every word of linewords)
set cust to ""
set j to j + 1
set photos to {""}
repeat with myItem in lineitems
if j > 1 then
copy myItem to the end of photos
else
set cust to word 1 of lineitems
end if
end repeat
end repeat
set AppleScript's text item delimiters to {""}
end tell
Of course, this script is far from complete; on top I am stuck to the fact that lineitems is always a list of 1 item, and is never able to be parsed - using words for example.
I just can’t figure out what I am doing wrong with the parsing of the strings in the CSV.
Also, any pointers on how I can continue with handling the filenames are more than welcom.
Any help would be greatly appreciated.
Thanks in advance,
Vangelis