Below is my code. I think it is right. It does everything it is supposed to. It just doesn’t do it in the correct order.
I have a folder full of pictures (screenshots converted to TIFs) that need to be renamed using a convention of a 3-letter prefix, followed by a 4-digit number, followed by a “type” code, and finally the ‘.tif’ ending. The pics are named “Picture 001, Picture 002,…Picture 111”. All 111 pics in the order they need to be in. However, the renamed pics won’t be starting at abc0001G.tif. They may need to start at, say, abc0085G.tif because of previous pics in the series.
Problem is that when I run this code on a set of pics (or any files) it does not rename the files starting with the first in the folder. I REALLY NEED for it to start with the first file in the folder, then do the second, then the third, and so on until all 111 are renamed consecutively.
Any and all help appreciated. I know this board has not been getting much traffic lately, but I do know that some of you are freaking geniuses at this stuff. Please share the wealth of that genius for a simple applescripter-wannabe.
CODE START
set theFolder to (choose folder with prompt “Please select the folder containing the files to rename.”)
set theIdentifierCode to choose from list {“G”, “C”, “L”, “K”} with prompt “Please select the indentifer code.”
set the3letterPrefix to text returned of (display dialog “Please enter in a 3 letter prefix.” default answer “xxx” buttons {“Cancel”, “Enter”} ¬
default button “Enter”) --here we will ask the user for the 3 letter character code.
if length of the3letterPrefix is greater than 3 then --if more than 3 characters were entered, such as “xyza” then…
set the3letterPrefix to (characters 1 through 3 of the3letterPrefix) as string --we will just get the first 3 characters.
else
if length of the3letterPrefix is less than 3 then -- but if less than 3 characters were entered, such as "xy" then...
set the3letterPrefix to characters of the3letterPrefix --here we will temporarily turn "xy" into {"x", "y"}
repeat (3 - (length of the3letterPrefix)) times --3 minus the number of characters we have (2 in this case ) is 1 so...
set the3letterPrefix to the3letterPrefix & "x" --we will add 1 (or the appropriate ammount of "x"s) to the 3 letter prefix
end repeat
end if
end if
set the3letterPrefix to the3letterPrefix as string --we will change {“x”, “y”, “x”} into “xyx”
set StartNum to display dialog “Please enter the starting number if other than 1.” default answer “1”
set theStartNum to text returned of StartNum
set theStartNum to theStartNum as integer
tell application “Finder”
if theStartNum > 1 then
set currentNumber to (theStartNum - 1)
else
set currentNumber to 0
end if
set miscFileCount to 0
set theReturned to {}
repeat with aFile in theFolder
set currentNumber to currentNumber + 1
set theName to the3letterPrefix & (my insertLeadingZeroes(currentNumber, 4)) & theIdentifierCode & ".tif"
set theName to theName as string
set name of file (aFile as alias) to theName
end repeat
end tell
on insertLeadingZeroes(thestring, numb)
set thestring to thestring as string
repeat until length of thestring is numb
set thestring to “0” & thestring
end repeat
return thestring
end insertLeadingZeroes
END OF CODE
Thank you,
Jmax