Help! Resize & Upload images script fails only about 50% of the time!

Hello to all,

I am a scripting newbie, and I am in need of some help. I wrote a script (droplet) to take any number of images that are dropped onto the icon, duplicate them into a new folder (so there are originals that are untouched), scale the images using ImageEvents, then upload the web-friendly sized pics to an afp mounted share point.

The script works many times, but often it fails! I cannot figure out a rhyme or reason to why it fails. I used a bunch of on error commands to help me determine WHERE the script breaks down (it is notated in the script), but I cannot figure out WHY it fails sometimes and other times it works like a charm.

Any help would be appreciated.

Thank you,

Dave Huber
(script below)


--if they double-click it, gently chastise them
on run
	display dialog "No no no, silly!  Don't double-click me...drag pictures on top of me!" buttons {"DOH!"} default button 1
end run

on open draggedItems
	
	
	try
		--mount the share point 
		mount volume "afp://server/sharepoint" as user name "user" with password "password"
	on error
		display dialog "couldn't mount the share point"
	end try
	
	
	try
		--define the upload folder
		set upload_folder to "sharepoint:images"
		
		
		--get ready to make a folder...
		
		--get time into text format 
		set current_week_day to weekday of (current date) as text
		set current_day to day of (current date) as text
		set current_month to month of (current date) as text
		set current_year to year of (current date) as text
		set current_time to (time of (current date)) as text
		
		--put all of the date info into one term called "current_date"
		set current_date to current_week_day & " " & current_day & " " & current_month & " " & current_year & " " & current_time as text
		
		--make a folder called 'Originals B4 upload' plus current date
		set foldername to "Originals B4 upload " & current_date
		tell application "Finder" to make new folder at desktop
		set localfolder to the result as alias
		tell application "Finder" to set the name of localfolder to foldername
	on error
		display dialog "couln't make a folder with the current date in the name."
	end try
	

	--repeat these steps for each item dropped on the icon	
	repeat with currentFile in draggedItems
		
		try --make a copy of the pic in the folder we just created
			tell application "Finder"
				duplicate (currentFile as alias) to localfolder
			end tell
		on error
			display dialog "error duplicating the scaled image to joomla folder."
		end try
		
		

		--scale the image to a web-friendly size

		try
			tell application "Image Events"
				set openedFile to open (currentFile as alias)
			end tell
		on error
			display dialog "couldn't set openedFile to currentFile as alias...whatever that means."
		end try
		
		delay 2





		--NOTE - THIS IS WHERE THE SCRIPT FAILS!!!!!!

		try
			tell application "Image Events"
				scale openedFile to size 180
			end tell
		on error
			display dialog "couldn't scale the image"
		end try
--NOTE - THE ABOVE IS THE ERROR MESSAGE I GET ABOUT 50% OF THE TIME!!!


		
		try
			tell application "Image Events"
				save openedFile
			end tell
		on error
			display dialog "couldn't save the scaled image"
		end try
		
		try
			tell application "Image Events"
				close openedFile
			end tell
		on error
			display dialog "couldn't close the image"
		end try
		
		--upload the scaled image & move the local one to the trash
		try
			
			tell application "Finder"
				duplicate (currentFile as alias) to upload_folder
			end tell
		on error
			display dialog "error trying to upload the image to joomla"
		end try
		
		try
			tell application "Finder"
				delete (currentFile as alias)
			end tell
		on error
			display dialog "couldn't move current file to the trash."
		end try
		
		--we are done batch processing now...
	end repeat
	
	--eject the joomla disk
	
	try
		tell application "Finder"
			eject disk "joomla"
		end tell
	on error
		display dialog "couldn't eject the joomla disk."
	end try
	
	--notify the user
	tell application "SystemUIServer"
		activate
		display dialog "The image(s) you dragged onto the icon have been scaled and uploaded and can now be used in any story you'd like to publish.
	
	Furthermore, the scaled images have been moved to your trash and your originals have been moved to a new folder on the desktop called " & foldername buttons {"Groovy"} default button 1
	end tell
	
end open


Model: PowerBook G4
AppleScript: 1.10.7
Browser: Firefox 1.5.0.8
Operating System: Mac OS X (10.4)

Not that this is any help to your direct request, but I have never had any consistent luck with Image Events.

No rhyme or reason, but sometimes it just doesn’t work for me. I always thought it had something to do with the images I was using, but sometimes a particular image will process, other times it won’t.

-N

Image Events certainly some quirkiness associated with it. Nigel Garvey posted this script in another thread that has worked well for me to overcome some of the erratic behavior.

set main_path to (path to desktop as Unicode text)
set a to (choose file)
tell application "Image Events"
	close images
	set b to (open a)
	set {{c, d}, e} to {dimensions, resolution} of b
	scale b by factor 0.2
	set p to main_path & name of b
	save b in file p
	close b
	
	set b to (open file p)
	set {f, g} to dimensions of b
	close b
end tell

get {c, d, e, f, g}

The two main differences are the close images and save b in file p commands. Try those out in your script and see if that improves reliability.

Some snippets of the script aboved worked like a charm, and it also allowed me to get rid of some bloat in my own script. THANKS SO MUCH FOR THE HELP!!!

-Dave