Replace one specific digit in a file

Hi there,

could somebody pleeeease help me with this one, I’m 100% new to AppleScripting…

My Sony DSC-V1 digicam creates file names with DSC and 5 digits, like DSC09839.JPG.

For some unexplicable reason however, after DSC09999.JPG did not come DSC10000.JPG, but it jumped back to DSC00000.JPG …

Now I thought it would be handy to have a little AppleScript that I could right-click-integrate with OMC doing the following:

Take the files that are currently selected in the finder window and for each one of them replace the 4th character from the start with a “1”… again, to transform a DSC00010.JPG into DSC10010.JPG . . .

How do I do that?

Thanks a million for your help !!!

Hi floz,

you can use this droplet. Save it as an application
and just drop the files on it

on open these_items
	repeat with this_item in these_items
		if folder of (info for this_item) is false then
			tell application "Finder"
				set this_name to name of this_item
				set name of this_item to (text 1 thru 3 of this_name) & "1" & (text 5 thru -1 of this_name)
			end tell
		end if
	end repeat
end open

Edit: and here a version to integrate in OMC

tell application "Finder"
	set these_items to selection
	repeat with this_item in these_items
		if class of this_item is document file then
			set this_name to name of this_item
			set name of this_item to (text 1 thru 3 of this_name) & "1" & (text 5 thru -1 of this_name)
		end if
	end repeat
end tell

Cheers mate, works perfect. Exactly what I wanted, thanks a million!