Repeat Numbers sequentially

Hello all,

I could use some help building a script to create a “numbering system” that would start at a given point (ex.1234) and the next time the script is run to use "1235, and then 1236, and so on. If anyone could assist I would greatly appreciate.

tell application "Finder"
	display dialog "Image Naming Script" buttons {"OK"} default button "OK"
set myDatabase to {"Towels"}
	set myChoice to (choose from list myDatabase)
	if (myChoice as string) is equal to "Towels" then display dialog "Towels Database. Prefix is: T.O." default answer "1668"
	set counter to text returned of result as number
	set counter to counter + 1
end tell


Model: G5 Pwer PC
Browser: Firefox
Operating System: Mac OS X (10.4)

The simpliest way is through Propreties as they retain state across runs. The problem though is that making any changes to the script resets your properties . so run this a few times

property c : 0

set c to c + 1
display dialog "Script has been run " & c & " times."

Then go make a single change to the display dialog, such as removing the period, and then run it again. The counter resets.

Perfect James! Thanks for the advice

Hi tringo19

I went through this exercise a while back, this thread may be of some use to you


Don’t know if you are still around. Your answer worked perfectly, but if I wanted to stop the number at 200 how would that look?


Hi Tringo, like this (will continue to run, but stop counting at 200)

property c : 0

if c < 200 then set c to c + 1
display dialog "Script has been run " & c & " times."

Ofcourse making that change will clear c’s value back to 0, but then will continue to hold value as normal. Or did you mean not to run past 200? That would be like this.

property c : 0

if c < 200 then
	set c to c + 1
	display dialog "Script has been run " & c & " times."
	display dialog "Evaluation over"
end if

Or a better way would be to take the functional code out of the if block and do this

property c : 197

if c = 200 then
	display dialog "Evaluation Over"
end if

set c to c + 1
display dialog "Script has been run " & c & " times."

thanks again for the assistance. The second option is what I was looking for. To number files as if in a pool, for multiple users. This way in a pool they will never be assigned the same number. And some sort of notification as to when they have used the last number. Thanks again for your help.


Note that version 2 and 3 accomplish the same task. I would prolly go with version 3 of the two though as they remove the functional code from within a If block… May not make a difference, but to me that code is cleaner.


If you use a good naming convention for your files, you don’t need to keep track of the number of the last file. You can just get the last file’s name.