Progress bar for a droplet

Hi,

I am new to AppleScript Studio. As an exercise I was trying to make a progress bar for an applescript which batch converts files to jpgs. Somehow I can’t seem to get it work. It works fine as a normal application. Would appreciate some help.

Thanks
Kaushik

-- iDrop.applescript
-- iDrop

--  Created by Kaushik Saha on 19/08/07.
--  Copyright 2007 __MyCompanyName__. All rights reserved.

global destination_folder

on open target_files
	
	set the maximum value of progress indicator "bar" of window "main" to the length of target_files
	
	repeat with a_File in target_files
		set file_path to a_File as string
		with timeout of 900 seconds
			tell application "Image Events"
				launch
				set the_image to open file file_path
				save the_image as JPEG in destination_folder with icon
				close the_image
			end tell
		end timeout
		
		repeat with i from 1 to the length of target_files
			set content of text field "txt" of window "main" to "Processing item " & i & " of" & (length of target_files) & "..." & return & (item i of target_files) as string
			
			set delayUntil to (current date) + 1
			repeat until (current date) is greater than or equal to delayUntil
			end repeat
			set content of progress indicator "bar" of window "main" to i
			
			
			
		end repeat
	end repeat
	
	
	stop progress indicator "spinner" of window "main"
	
	quit
end open

on awake from nib theObject
	set destination_folder to choose folder with prompt "Choose a folder to save the jpgs:" as string
	start progress indicator "spinner" of window "main"
	set content of progress indicator "bar" of window "main" to 0
	start progress indicator "bar" of window "main"
	
end awake from nib

on idle theObject
	(*Add your script here.*)
end idle