Here is my script it half works at the moment, it uses exiftool to restamp images. but when it then attempts to move the file from A > B they sometimes have the same filename so the handler adds “_a” etc. it get stuck at the moment as soon as it gets to the “_b” and it can’t shift it over.
Where am I going wrong?
tell application "Finder"
set this_folder to (alias ((path to pictures folder as text) & "HELICON"))
set itemList to every file in this_folder
set theHotFolder to folder "Hal 9000:Users:matthew:Desktop:HotFolder"
repeat with i from 1 to count of itemList
set newFile to item i of itemList as alias
set theFile to POSIX path of newFile
set theCreator to do shell script "/usr/bin/exiftool -ownername " & quoted form of theFile
if theCreator is equal to "" then
do shell script "/usr/bin/exiftool -overwrite_original -DocumentName='HeliconFocus' -ownername='Photographed_by_Me' " & quoted form of theFile
delay 5 -- time here is needed to rewrite the file or ot won't move
try
move newFile to theHotFolder
on error
set {fileName, t_ext} to {name, name extension} of newFile
set newName to my getUniqueName(fileName, t_ext, theHotFolder)
set name of file fileName of this_folder to newName
end try
else
try
move newFile to theHotFolder
on error
set {fileName, t_ext} to {name, name extension} of newFile
set newName to my getUniqueName(fileName, t_ext, theHotFolder)
set name of file fileName of this_folder to newName
end try
end if
end repeat
end tell
to getUniqueName(theName, theExtension, someFolder)
(*
check if someFile exists in someFolder, creating a new unique file name (if needed) by adding a suffix
parameters - theName, theExtension : a file name and his name extension
someFolder : a folder (finder item or alias)
returns : a unique name
*)
set {counter, suffixes, divider} to {0, "abcdefghijklmnopqrstuvwxyz", "_"}
if theExtension is not "" then set theExtension to "." & theExtension
set theName to text 1 thru -((length of theExtension) + 1) of theName -- just the name part
set newName to theName & theExtension
tell application "Finder" to set theseNames to name of items of someFolder
repeat while theseNames contains newName
set counter to counter + 1 -- hopefully there aren't more than 26 duplicates (numbers are easier)
set newName to theName & divider & (item counter of suffixes) & theExtension
end repeat
return newName
end getUniqueName