Simple iSightcapture scripting problem

I have a CLI tool called iSightcapture that takes a snapshot of my iSight or any other video input. What I’m trying to do is the following: I have a Powermate that I’m using as a foot pedal which activates Proxi which performs the following script (suggested by someone esle):

tell application “Finder”
if exists item “webcam.jpg” then
set my_number to 1
repeat
try
set name of item “webcam.jpg” to ("webcam " & my_number & “.jpg”)
exit repeat
on error
set my_number to my_number + 1
end try
end repeat
end if
end tell
do shell script “~/bin/isightcapture ~/Desktop/webcam.jpg”

It works well to place sequential JPGs on my desktop, but it keeps renaming the original file, such that a new snapshot is named webcam.jpg, and the previous webcam.jpg is renamed webcam1.jpg, etc.

I have it modified to save the JPG in a file “Attachements” on my desktop. When my medical software detects a new file in this folder, it automatically imports it into the database, and deletes the original. If I take another picture, the script renames the first file while it’s being imported, and for some reason, I have to wait until the entire import process is finished (about 5-10 seconds) before I can take another picture. I wish I could palce successive pictures one after the other (with different names) in this folder. I tested palcing multiple files simultaneosuly and my meidcal program imports them just fine.

Thanks for your help.

Steve

p.s. Sorry, but I’m a newbie.

I don’t have a way to test it, but something like the following may work:

-- Initial prep
set deskpath to (path to desktop) as Unicode text
set myfile to "webcam"
set overwrite to ""
set newpart to ""

-- check to see if file exists
-- if so, add numbers to file name.
repeat until overwrite = "no"
	tell application "Finder"
		if (file (deskpath & myfile & newpart & ".jpg") exists) is true then
			set newpart to newpart + 1
		else
			set overwrite to "no"
		end if
	end tell
end repeat

-- Create new file name
set filename to myfile & newpart & ".jpg"
do shell script "~/bin/isightcapture " & deskpath & filename