adding a number to another number

Hello:
I need to write a script that will add 48 to whatever number is already on some files.
I have PDFs that are labeled 1-100 with the number being in a 3 digit prefix.
So, I have a file called 010_help.PDF and I need to be able to run a script and temporarily change this file to be 058_help.PDF. And then later run a reverse script and come back and delete 48 from the number to turn it back into page 10.
Suggestions?
/curtis

Hi curtis,

try this subroutine, it can do both


on add_subtract_48 from theString given add:add
	tell theString to set {pre, suf} to {(text 1 thru 3) as number, text 4 thru -1}
	if add then
		set pre to pre + 48
	else
		set pre to pre - 48
	end if
	return text -3 thru -1 of ("000" & (pre as text)) & suf
end add_subtract_48


add_subtract_48 from "010_help.pdf" with add --> 058_help.pdf

add_subtract_48 from "067_whatever.pdf" without add --> 019_whatever.pdf

Here’s a script I use to change the name of a file, which if combined with StefanK’s script you have what you need.

set thisitem to choose file
set newname to "test.txt"

my set_item_name(thisitem, newname)

on set_item_name(this_item, new_item_name)
	set this_item to this_item as Unicode text
	tell application "Finder"
		set parent_container_path to (container of item this_item) as text
		if not (exists item (parent_container_path & new_item_name)) then
			try
				set the name of item this_item to new_item_name
			on error the error_message number the error_number
				if the error_number is -59 then
					set the error_message to "This name contains improper characters, such as a colon (:)."
				else --the suggested name is too long
					set the error_message to error_message -- "The name is more than 31 characters long."
				end if
				tell me to display dialog the error_message default answer new_item_name buttons {"Cancel", "Skip", "OK"} default button 3
				copy the result as list to {new_item_name, button_pressed}
				if the button_pressed is "Skip" then return 0
				my set_item_name(this_item, new_item_name)
			end try
		else --the name already exists
			tell me to display dialog "This name is already taken, please rename." default answer new_item_name buttons {"Cancel", "Skip", "OK"} default button 3
			copy the result as list to {new_item_name, button_pressed}
			if the button_pressed is "Skip" then return 0
			my set_item_name(this_item, new_item_name)
		end if
	end tell
end set_item_name