error checking issue

Hi,

I have a long script that does a whole bunch of stuff including resizing images via Image Events

To error check globally the whole script I have enclosed in a try block.

The problem I have is that though the script without the try block runs perfectly when the try block is included it fails at the same place…when the image events handler is invoked. I have tried timeout around and inside the handler but to no avail.

Could you please cast your eyes over this and see if there is a workaround

snippet


repeat with i from 1 to the number of items in images_selected
		set curImage to item i of images_selected as Unicode text
		set image_file_path to (c_hosen & curImage as string)
			resizeGroup(image_file_path, saveFilePath)
	end repeat

the handler – the other save variables are global variables


on resizeGroup(this_item, saveFilePath)
	
		tell application "Image Events"
			launch
			set this_image to open this_item
			--resize the image
			scale this_image to size theResize2
			save this_image as JPEG in PrintFolder with compression level medium
			
			scale this_image to size theResize
			save this_image as JPEG in saveFilePath with compression level medium
			scale this_image to size theResize
			save this_image as JPEG in webFolder with compression level medium
			close this_image
		end tell

end resizeGroup

the event log at faliure

tell application “Image Events”
launch
current application
open “Clarks Laptop:Users:JCLAPTOP:PhotoData_Laptop:Clients:aaaa bbbbbbb_JC5131:Original Files:1_AABB_JC5131.JPG”
image “1_AABB_JC5131.JPG”
scale image “1_AABB_JC5131.JPG” to size 1400
end tell
tell current application
activate
beep 3
display dialog “Please re-import your images.” buttons {“Re-Import”, “Cancel”} cancel button {“Cancel”} default button 1 giving up after 9000000
“User canceled.”

THanks in advance

Hi,

it’s hard to judge it without the crucial try block

Here goes…


property groupNum : 5
property theResize : 600
property theResize2 : 1400

--filemaker properties change to Laptop_Data or Group_Data or Stage_Data
property myfile : "Group_Data"
property mylayout : "FORM"
property images : "Laptop_images"
property contactSheet : "ContactSheet"



--checks folders installed
set pathto to path to home folder from user domain
try
	set processimages to (pathto & "PhotoData_Laptop:Process folder:" as string) as alias
	set backup to (pathto & "PhotoData_Laptop:Backup Images:" as string) as alias
	set Pathtoclients to (pathto & "PhotoData_Laptop:Clients:" as string) as alias
	set Pathtoselected to (pathto & "PhotoData_Laptop:Selected images:" as string) as alias
	set Pathtowebfolder to (pathto & "PhotoData_Laptop:Upload WebFolder Groups:" as string) as alias
	set PathtoPrint to (pathto & "PhotoData_Laptop:Print Folder Groups:" as string) as alias
	
on error
	display dialog "You do not have the correct folders installed. Install Now?" buttons {"Yes"} cancel button {"No"}
	try
		set photofolderlist to {"Process folder", "Clients", "Backup Images", "Selected images", "Print Folder Groups", "Upload Webfolder Groups"}
		set pathtophotodata to (pathto & "PhotoData_Laptop:" as string)
		FOLDERMAKER(pathtophotodata, photofolderlist)
	on error
		display dialog "PhotoData folder not installed. Install now and rerun the script" buttons {"Yes"}
		set photofolderlist to {"PhotoData_Laptop"}
		FOLDERMAKER(pathto, photofolderlist)
	end try
	
end try


global backup, processimages, Pathtoclients, Pathtowebfolder, PathtoPrint

--checks process folder

set holdit to list folder processimages without invisibles
if (count of holdit) is greater than 0 then
	tell application "Finder"
		activate
		beep 3
		reveal processimages
		display dialog "You have images in your process folder. Please check that folder and re import" buttons {"Cancel"} cancel button {"Cancel"} default button 1
	end tell
	
end if

--choose folder to import images from
tell current application
	activate
	beep 2
	set fromcamera to choose folder with prompt "Choose a folder from which to process images"
end tell

--check number of images for group sessions

fiveormore(fromcamera)

set num to checkNOimages(fromcamera)
display dialog "You have " & num & " images to process.
Continue?"

--collect Filemaker Data
try
	tell application "FileMaker Pro Advanced"
		go to database myfile
		show layout mylayout
		set FullName to cell "unique_id" of current record
		set first_name to cell "fname" of current record
		--use in new site
		set Low_er to cell "unique_id" of current record
		--old site parameters
		--set Low_er to cell "l_ower" of current record
		
		set clientid to cell "client_id" of current record
		set s_hort to cell "shortname" of current record
	end tell
	
	--create checkimage list
	set imageCheckList to createImageCheckList(clientid, s_hort, fromcamera)
	imageCheckList
	
	--copy images to HD
	tell application "Finder"
		activate
		duplicate every item of fromcamera to processimages
		set cameradisk to name of disk of fromcamera
	end tell
	
	--name images
	set listimages to list folder processimages without invisibles
	nameimages(listimages, clientid, s_hort)
	set newImageList to list folder processimages without invisibles
	--image name check
	checklists(newImageList, imageCheckList, clientid)
	
	(*
--create records
createrecords(clientid, processimages)
*)
	
	--create client, web and print folders
	
	set photofolderlist to {FullName}
	FOLDERMAKER(Pathtoclients, photofolderlist)
	set newPath1 to (Pathtoclients & FullName as string)
	
	set photofolderlist to {"Original Files", "Web Site", "RGB"}
	FOLDERMAKER(newPath1, photofolderlist)
	
	set newPath2 to (Pathtoclients & FullName & ":Web Site:" as string)
	set photofolderlist to {Low_er}
	FOLDERMAKER(newPath2, photofolderlist)
	
	set photofolderlist to {FullName}
	FOLDERMAKER(Pathtowebfolder, photofolderlist)
	
	set photofolderlist to {FullName}
	FOLDERMAKER(PathtoPrint, photofolderlist)
	
	-- move images to client folder
	copyimages(FullName, Pathtoclients)
	
	
	--create contact sheet images
	
	set c_hosen to (Pathtoclients & FullName & ":Original Files:" as string)
	set saveFilePath to (Pathtoclients & FullName & ":Web Site:" & Low_er & ":" as string)
	
	set webFolder to (Pathtowebfolder & FullName & ":" as string)
	set PrintFolder to (PathtoPrint & FullName & ":" as string)
	
	global PrintFolder, webFolder
	
	set images_selected to list folder c_hosen as Unicode text without invisibles
	repeat with i from 1 to the number of items in images_selected
		set curImage to item i of images_selected as Unicode text
		set image_file_path to (c_hosen & curImage as string)
		
		--studio clients processing
		--processcontactimages(image_file_path, saveFilePath)
		
		--groupclients processing
		
		resizeGroup(image_file_path, saveFilePath)
		
	end repeat
	
	--create image records and pdf
	tell application "Finder"
		set mDisk to name of startup disk
	end tell
	global mDisk
	
	set listHiRes to list folder webFolder without invisibles
	repeat with i from 1 to number of items in listHiRes
		set this_item to item i of listHiRes
		
		set image_file_path to (webFolder & this_item as string)
		tell application "Finder"
			
			if name extension of alias image_file_path is "jpg" then
				
				set UnixPath to mDisk & (POSIX path of image_file_path as Unicode text)
				
				image_file_path as file specification
				
				my FM_Insert(UnixPath, this_item, clientid)
			end if
		end tell
	end repeat
	
	-- create CSV file
	
	tell application "FileMaker Pro Advanced"
		go to database myfile
		go to layout mylayout
		--set FullName to cell "unique_id" of current record
		--set pathtext to (Pathtoclients & FullName & ":" as text)
		--set cell "path" of current record to pathtext as text
		show (every record of table myfile whose cell "unique_id" = FullName)
		do script "export_csv"
		tell layout contactSheet
			do script "createNewRecordcontact"
			set cell "clientid" of current record to clientid
			do script "createPDF"
		end tell
		
	end tell
	--move PDF to correct folder
	set processimages to (pathto & "PhotoData_Laptop:Process folder:" as string) as alias
	set x to list folder processimages without invisibles
	repeat until (count of x) > 0
		set x to list folder processimages without invisibles
		if (count of x) is 0 then
			delay 0.1
		end if
	end repeat
	
	tell application "Finder"
		set targetfile to entire contents of processimages as alias
	end tell
	set newname to (FullName & ".pdf" as string)
	changename(newname, targetfile)
	moveitems(processimages, PrintFolder)
	--delete images from card
	
	--temporary move website
	(*set webPath to (newPath2 & Low_er as string)
set newwebfolder to (newPath1 & ":NewContactSheet:" as string)
tell application "Finder"
	move every file of folder webPath to newwebfolder
end tell*)
	--error checking images
	
	tell application "System Events"
		
		set list2 to the name of every file of alias webFolder whose name extension is "jpg"
	end tell
	checklists(imageCheckList, list2, webFolder)
	
	
	
	tell application "System Events"
		
		set list2 to the name of every file of alias PrintFolder whose name extension is "jpg"
	end tell
	checklists(imageCheckList, list2, PrintFolder)
	
	tell application "System Events"
		
		set list2 to the name of every file of alias c_hosen whose name extension is "jpg"
	end tell
	checklists(imageCheckList, list2, c_hosen)
	
	tell application "System Events"
		
		set list2 to the name of every file of alias saveFilePath whose name extension is "jpg"
	end tell
	checklists(imageCheckList, list2, saveFilePath)
	
	--error checking csv
	set CSV to {"clientData.csv"}
	tell application "System Events"
		
		set list2 to the name of every file of alias webFolder whose name extension is "csv"
	end tell
	set CSV to {"clientData.csv"}
	checklistsCSV(CSV, list2, webFolder)
	
	tell application "System Events"
		
		set list2 to the name of every file of alias saveFilePath whose name extension is "csv"
	end tell
	set CSV to {"clientData.csv"}
	checklistsCSV(CSV, list2, saveFilePath)
	
	tell application "FileMaker Pro Advanced"
		go to database myfile
		go to layout mylayout
	end tell
	
	
	
	
	tell application "Finder"
		activate
		display dialog "Your images are copied.
You can eject disk and leave the images on it or trash the images and eject the disk." buttons {"Eject disk", "Trash Images"} default button 2 giving up after 10000 with icon 2
		--trash images from card
		if the button returned of the result is "Trash Images" then
			beep 3
			display dialog "This action permantley deletes images from your disk. Are you sure?" giving up after 10000 with icon 2
			delete every item of fromcamera
			try
				empty trash
				delay 1
				set y to "Trash"
				set x to name of every window
				
				repeat until x does not contain y
					set x to name of every window
					
					delay 0.2
					
				end repeat
				eject disk cameradisk
				display dialog (num & " images for " & FullName & " have been processed, the images deleted and the disk has been ejected" as string) with icon 1 giving up after 10000
				
			on error the error_message number the error_number
				display dialog "Error: " & the error_number & ". " & the error_message & "Please manually eject your disk" buttons {"Cancel"} default button 1 giving up after 10000 with icon 2
			end try
		else
			try
				eject disk cameradisk
			on error the error_message number the error_number
				display dialog "Error: " & the error_number & ". " & the error_message & "Please manually eject your disk" buttons {"Cancel"} default button 1
			end try
			display dialog (num & " images for " & FullName & " have been processed with the images saved to disk. The disk has been ejected" as string) with icon 1 giving up after 100000
		end if
	end tell
	
on error
	
	--if all else fails.......
	
	set xxlist to list folder fromcamera without invisibles
	set webFolder to (Pathtowebfolder & FullName & ":" as string)
	set PrintFolder to (PathtoPrint & FullName & ":" as string)
	
	if xxlist is equal to {} then
		display dialog "WARNING: Your images have been deleted from your camera card. They should have been copied to you HD. Please check your folders and make sure you have them" buttons {"Cancel"} cancel button {"Cancel"}
	end if
	
	set xxfolder to (Pathtoclients & FullName as string)
	deleteFolder2(webFolder)
	deleteFolder2(PrintFolder)
	deleteFolder2(xxfolder)
	deleteFolder(processimages)
	
	
	tell me to activate
	beep 3
	display dialog "Please re-import your images." buttons {"Re-Import", "Cancel"} cancel button {"Cancel"} default button 1 giving up after 9000000
	
	if the button returned of the result is "Re-Import" then
		tell application "FileMaker Pro Advanced"
			go to database myfile
			show layout mylayout
			do script "process from camera_Laptop"
		end tell
	end if
end try
--temporary move items
(*tell application "Finder"
	move every file of folder webPath to newwebfolder
end tell*)

on processcontactimages(this_item, saveFilePath)
	tell application "Image Events"
		launch
		
		set this_image to open this_item
		
		tell this_image
			--set {x, y} to dimensions of this_image
			scale this_image to size 600
			save this_image as JPEG in saveFilePath with compression level medium
			close this_image
		end tell
		(*tell application "Adobe Photoshop CS3"
			activate
			if y > x then
				open alias this_item
				do action "create_biColor_Horizontal" from "Contact_Sheet_Images"
			else
				open alias this_item
				do action "create_biColor_Vertical" from "Contact_Sheet_Images"
			end if
			save current document in saveFilePath as JPEG
			close current document
			
		end tell*)
		
		
	end tell
	
end processcontactimages
on copyimages(FullName, Pathtoclients)
	set originalfolder to alias (Pathtoclients & FullName & ":Original Files:" as string)
	
	tell application "Finder"
		activate
		try
			duplicate every item of processimages to originalfolder
			
		on error the error_message number the error_number
			activate
			display dialog "Error: " & the error_number & ". " & the error_message buttons {"Cancel"} default button 1
		end try
	end tell
	set q to list folder processimages without invisibles
	set w to list folder originalfolder without invisibles
	if q is equal to w then
		tell application "Finder"
			activate
			try
				move every item of processimages to backup with replacing
				
			on error the error_message number the error_number
				activate
				display dialog "Error: " & the error_number & ". " & the error_message buttons {"Cancel"} default button 1
				
			end try
			
		end tell
	else
		activate
		display dialog "There are other images in " & FullName & " folder. Please go to the original files folder of this client and check the images" with icon 2 giving up after 3000
	end if
	
end copyimages

on deleteFolder(delete_file)
	tell application "Finder"
		delete entire contents of delete_file
	end tell
end deleteFolder



on nameimages(listimages, clientid, s_hort)
	
	set c_ount to 0
	
	repeat with i from 1 to the count of listimages
		set image1 to item i of listimages
		set c_ount to c_ount + 1
		
		set p_ath to alias (processimages & image1 as Unicode text)
		
		tell application "Finder"
			set file_extension to the name extension of p_ath
			set name of p_ath to (c_ount & "_" & s_hort & "_" & clientid & "." & file_extension as Unicode text)
			set this_item to (name of p_ath as string)
		end tell
	end repeat
end nameimages
on createrecords(clientid, processimages)
	set listprocess to list folder processimages without invisibles
	repeat with i from 1 to the count of listprocess
		set this_item to item i of listprocess
		tell application "FileMaker Pro Advanced"
			go to database myfile
			go to layout images
			create new record with data {this_item, clientid}
		end tell
	end repeat
end createrecords



on createImageCheckList(clientid, s_hort, pathtoImages)
	set imageCheckList to {}
	set countNum to 0
	set listimages to list folder pathtoImages without invisibles
	set num to count of listimages
	repeat with i from 1 to number of items in listimages
		set counter to countNum + 1
		set this_item to item i of listimages
		set this_item to alias (pathtoImages & this_item as string)
		set fileEXT to getFileextension(this_item)
		set newname to (counter & "_" & s_hort & "_" & clientid & "." & fileEXT as string)
		
		set end of imageCheckList to newname
		set countNum to counter
		-- insert actions here
	end repeat
	return imageCheckList
end createImageCheckList
on getFileextension(pathtofile)
	tell application "Finder"
		set file_extension to the name extension of pathtofile
	end tell
	return file_extension
end getFileextension

on checkNOimages(fromcamera)
	tell application "Finder"
		set l_ist to list folder fromcamera without invisibles
		set num to count of items in l_ist
		return num
	end tell
end checkNOimages
on fiveormore(fromcamera)
	tell application "Finder"
		set l_ist to list folder fromcamera without invisibles
		set num to count of items in l_ist
		if num is not equal to groupNum then
			beep 3
			display dialog "You have " & num & " images to import" & return & "You should have " & groupNum & return & "Do you wish to continue? Press Cancel to Stop" default button 1 with icon 2
			beep 3
			display dialog "Are you sure you wish to continue? You have  " & num & " images in the folder.
Hit cancel to quit or OK to continue" default button 1 with icon 2
		end if
	end tell
	return num
end fiveormore

on FOLDERMAKER(p_ath, folderlist)
	repeat with i from 1 to number of items in folderlist
		set foldername to item i of folderlist
		tell application "Finder"
			make new folder at p_ath with properties {name:foldername}
		end tell
	end repeat
end FOLDERMAKER
on deleterecords(clientid)
	tell application "FileMaker Pro Advanced"
		go to database myfile
		show layout images
		show (every record of table images whose cell "client_id" = clientid)
		delete every record of document 1
	end tell
end deleterecords

on checklists(list1, list2, folderpath)
	set num1 to count of items in list1
	set num2 to count of items in list2
	if num1 = num2 then
		repeat with i from 1 to (length of list1)
			set thislistitem1 to item i of list1
			
			set result to list2 contains thislistitem1
			if result = false then
				
				set badname to item i of list1
				display dialog badname & " of database is a problem" buttons {"Cancel"} cancel button {"Cancel"} default button 1
				
			end if
		end repeat
		repeat with i from 1 to (length of list2)
			set thislistitem1 to item i of list2
			
			set result to list1 contains thislistitem1
			if result = false then
				
				set badname to item i of list2
				display dialog badname & " of " & folderpath & " is a problem" buttons {"Cancel"} cancel button {"Cancel"} default button 1
				
			end if
			
		end repeat
		
	else
		display dialog "You have a problem." & return & "Check file names?" buttons {"Yes", "No"} cancel button {"No"}
		set theResult to the button returned of the result
		if theResult = "Yes" then
			if num1 > num2 then
				repeat with i from 1 to (length of list1)
					set thislistitem1 to item i of list1
					
					set result to list2 contains thislistitem1
					if result = false then
						
						set badname to item i of list1
						display dialog badname & " of database is a problem" buttons {"Cancel"} cancel button {"Cancel"} default button 1
					end if
				end repeat
			else
				if num1 < num2 then
					repeat with i from 1 to (length of list2)
						set thislistitem1 to item i of list2
						
						set result to list1 contains thislistitem1
						if result = false then
							
							set badname to item i of list2
							display dialog badname & " of " & folderpath & " is a problem" buttons {"Cancel"} cancel button {"Cancel"} default button 1
						end if
					end repeat
				end if
			end if
		end if
	end if
end checklists

on resizeGroup(this_item, saveFilePath)
	
		tell application "Image Events"
			launch
			set this_image to open this_item
			--resize the image
			scale this_image to size theResize2
			save this_image as JPEG in PrintFolder with compression level medium
			
			scale this_image to size theResize
			save this_image as JPEG in saveFilePath with compression level medium
			scale this_image to size theResize
			save this_image as JPEG in webFolder with compression level medium
			close this_image
		end tell

end resizeGroup

on FM_Insert(path1, fileName, clientid)
	tell application "FileMaker Pro Advanced"
		tell layout images
			
			do script "createNewRecordimages"
			--set curRec to current record as reference
			set cell "client_id" of current record to clientid
			
			set cell "picturePath" of current record to path1
			set cell "filename" of current record to fileName
			
			do script "Insert Picture"
		end tell
	end tell
	
end FM_Insert

on changename(newname, targetfile)
	tell application "Finder"
		set name of targetfile to newname
	end tell
end changename
on moveitems(pathtosource, pathtomoveto)
	tell application "Finder"
		move every item of pathtosource to pathtomoveto
	end tell
	
end moveitems
on checklistsCSV(CSV, list2, folderpath)
	try
		if list2 does not contain CSV then
			
			tell application "FileMaker Pro Advanced"
				go to database myfile
				show layout mylayout
				do script "export_csv Copy"
			end tell
		end if
	on error
		display dialog ("Unable to ceate CSV file in " & folderpath as string)
	end try
	moveitems(processimages, folderpath)
	
end checklistsCSV

on deleteFolder2(delete_file)
	tell application "Finder"
		delete folder delete_file
	end tell
end deleteFolder2



oh my god :wink:

I personally don’t like these giant try blocks,
but it would be helpful to know the kind of the error


.
on error e
display dialog e
.

Sorry Stefan…

A bit like sitting through the entire Ring Cycle in one hit…

The error is in my first post

–The script get to to the Image Events handler and then…

tell application “Image Events”
launch
current application
open “Clarks Laptop:Users:JCLAPTOP:PhotoData_Laptop:Clients:aaaa bbbbbbb_JC5131:Original Files:1_AABB_JC5131.JPG”
image “1_AABB_JC5131.JPG”
scale image “1_AABB_JC5131.JPG” to size 1400
end tell

THROWS THE TRY BLOCK TO ERROR WHEN THERE APPEARS TO BE NO ERROR?!?!

tell current application
list folder alias “Clarks Laptop:Users:JCLAPTOP:PhotoData_Laptop:Selected images:” without invisibles
{“5_PAAS_1983.JPG”, “6_PAAS_1983.JPG”, “7_PAAS_1983.JPG”, “8_PAAS_1983.JPG”, “9_PAAS_1983.JPG”}
end tell
tell application “Finder”
delete folder “Clarks Laptop:Users:JCLAPTOP:PhotoData_Laptop:Upload WebFolder Groups:aaaa bbbbbbb_JC5131:”
folder “aaaa bbbbbbb_JC5131 19-57-18” of trash
delete folder “Clarks Laptop:Users:JCLAPTOP:PhotoData_Laptop:Print Folder Groups:aaaa bbbbbbb_JC5131:”
folder “aaaa bbbbbbb_JC5131 19-57-18 2” of trash
delete folder “Clarks Laptop:Users:JCLAPTOP:PhotoData_Laptop:Clients:aaaa bbbbbbb_JC5131”
folder “aaaa bbbbbbb_JC5131 19-57-18 3” of trash
delete entire contents of alias “Clarks Laptop:Users:JCLAPTOP:PhotoData_Laptop:Process folder:”
{}
end tell
tell current application
activate
beep 3
display dialog “Please re-import your images.” buttons {“Re-Import”, “Cancel”} cancel button {“Cancel”} default button 1 giving up after 9000000
“User canceled.”

Regards

Of course I read your posted log but I’m wondering if there is an error message at all,
which could be more significant than the log

Hi StefanK

There was no error message. Just as the Event Log