So, I want to version my files in a very simple manner (mostly indd)
So I start with filename.ext file name.
I want for this to be duplicated, and renamed filename r.ext (r for revised).
If I make another version, I want this to copy and be filename r2.ext (r2 for revised twice)
I’ve come up with the following code.
It works, but
-
I KNOW there’s a better way to do it, as I’m a junior-grade scriptor
-
I couldn’t figure out a sub-routine to handle the variations from no r, to r, to r2 and beyond, so i dropped the " r" and made the base " r1"
Hopefully that makes sense and you can help me clean this code up.
set OrigTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
tell application "Finder"
set ItemList to selection
repeat with i from 1 to number of items in ItemList
set thisItem to item i of ItemList
set sel_name to name of thisItem -- captures whole name name
display dialog sel_name
set Old_Name to first text item of sel_name --captures everything up to suffix
display dialog Old_Name
set Old_Type to second text item of sel_name
display dialog Old_Type
set AppleScript's text item delimiters to "" -- resets TIDs
set w_count to count text items of Old_Name -- counts number of letters in name
display dialog w_count
if w_count > 4 then
set LChar to text item w_count of Old_Name -- captures last character
display dialog LChar
set SLChar to text item (w_count - 1) of Old_Name -- captures 2nd to last letter
display dialog SLChar
set TLChar to text item (w_count - 2) of Old_Name -- captures 3nd to last letter
display dialog TLChar
set FLChar to text item (w_count - 3) of Old_Name -- captures 4nd to last letter
display dialog FLChar
set TLChar_set to TLChar & SLChar & LChar
display dialog TLChar_set
set Name_Thru to text items 1 thru (w_count - 3) of Old_Name as string
display dialog Name_Thru
set Poss_Suffix to {" r1", " r2", " r3", " r4", " r5", " r6", " r7", " r8", " r9"}
end if
if TLChar_set is not in Poss_Suffix then
set New_Name to Old_Name & " r1." & Old_Type
display dialog New_Name
else if TLChar_set is in Poss_Suffix then
set New_Suffix to " r" & (LChar + 1)
display dialog New_Suffix
set New_Name to Name_Thru & New_Suffix & "." & Old_Type
display dialog New_Name
end if
duplicate thisItem
set Copy_Item to selection as string
set name of file Copy_Item to New_Name
end repeat
end tell
Browser: Safari 525.13
Operating System: Mac OS X (10.5)