An example for a script to rename the files dropped on an applet or the files in a chosen folder is as follows.
property startStr : "001"
property nfSep : "-"
on run
try
set inputFolder to choose folder with prompt "Please select the folder containing the files to be numbered."
on error
return
end try
set nameStr to GetFolderName(inputFolder as text)
tell application "Finder"
set inputFiles to every file of inputFolder
end tell
RenameFiles(nameStr, inputFiles)
end run
on open fileList
set firstFileStr to (item 1 of fileList as text)
set nameStr to GetFolderName(firstFileStr)
RenameFiles(nameStr, fileList)
end open
on GetFolderName(theString)
set {oldTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
set strList to (text items of theString)
set nameString to (text item -2 of strList)
set AppleScript's text item delimiters to oldTIDs
return nameString
end GetFolderName
to RenameFiles(nfName, theFileList)
set nfNum to (text returned of (display dialog "Please enter the start number with all leading zeros." default answer startStr))
if nfNum is not equal to startStr then
set startStr to nfNum
end if
set startNumLength to (count of startStr)
try -- convert the starting value string into a number
set startNum to (startStr as integer)
on error -- the starting value string contained a non-number
display dialog "The value " & startStr & " is not a valid number." & return & "Please enter numbers only!" with icon stop buttons {"Sorry"} default button 1
end try
set zeroMask to ""
repeat startNumLength times
set zeroMask to (zeroMask & "0")
end repeat
set increment to 0
repeat with i from 1 to (count of theFileList)
set nf to (item i of theFileList)
tell application "Finder" to set fex to name extension of nf
set nfNum to (startNum + increment)
set nnStr to zeroMask & nfNum
set nextName to nfName & nfSep & (text -1 thru -(startNumLength) of nnStr)
tell application "Finder" to set the name of nf to (nextName & "." & fex)
set increment to (increment + 1)
end repeat
end RenameFiles