Okay…I’m revisiting this post a couple months later. I’ve had a change in my workflow. Instead of changing the file name from ending in 4c to BW or vice versa, I need to change the file name from ending in 4c to RGB or BW to RGB. I’ve combined my name changing script with a Folder Action script. Basically, this “Process Folder” acts as a holding place for JPGs that are processed offsite. When files are dropped into it, they are duplicated to an “Inbox” to be processed. Once processed, the file will appear in the “Outbox” and another script which watches the “Outbox” will do its thing, part of which deletes the file out of the “Process Folder” and then process is complete. I continually add photos to this “Process Folder”, so there’s a steady flow of photos going in and out.
So with my workflow change, I need to also duplicate a JPG whose name ends in RBG rather than 4c or BW to a different folder. The following script does exactly what I what (as long as I drop one JPGs at a time):
property origList : {"BWHT.jpg", "4cHT.jpg", "BWHTM.jpg", "4cHTM.jpg"}
property dupeList : {"RGB.jpg", "RGB.jpg", "RGB.jpg", "RGB.jpg"}
on adding folder items to this_folder after receiving added_items
tell application "Finder" to repeat with thisFile in added_items
if name of thisFile does not end with ".jpg" then
set NotJpg to name of thisFile
display dialog NotJpg & " is not a .JPG & was deleted from Process folder" with icon 0 buttons {"Oops!"} ¬
default button "Oops!"
delete thisFile
else
repeat with currEnd in {"ht.jpg", "htm.jpg"}
if name of thisFile ends with currEnd then
repeat with theItem in (get selection)
set currName to theItem's name
tell origList to repeat with i from 1 to count
tell item i to if currName ends with it then
set RGBFile to currName's text 1 through -((count) + 1) & "RGB.jpg"
set (duplicate theItem to RefreshMedia replacing yes)'s name to RGBFile
exit repeat
end if
end repeat
end repeat
end if
end repeat
end if
duplicate thisFile to Inbox
end repeat
end adding folder items to
However…if I drop more than one JPG at a time, let’s say 5, it’ll create 5 JPGs ending in RGB to the correct folder, but it’ll also duplicate one of the originally named files (ending in either 4c or BW) for a total of 6 duplicated files. It’s random as to which file it duplicates incorrectly (first, last, whichever).
Can anyone offer a suggestion as to what I’ve done wrong in my script? Also, is there a better way to define the files where I have:
repeat with theItem in (get selection)
I’m dying over here!
Thanks - slimjim5811