Problem with corrupt fonts and auto installer script

G’day.

The following is an automatic installer script for fonts sent in emails

Trouble is, we often get sent corrupt fonts, and haven’t been able to error trap them, and fontbook is going into an infinite loop trying to install something, but not sure what. No extra fonts show up on quitting it.

Turning off validation lets it work correctly, but we don’t want to install bad fonts.

Any suggestions please on how I can trap corrupt fonts?

Regards

Santa



on SecondAttachmentPrintCycle()
	tell application "Finder"
		try
			set NewFontInstalled to false
			tell application "Finder" to set theFonts to (get files of entire contents of folder holding_folder whose kind contains "font")
			if (count theFonts) > 0 then
				try
					tell application "Font Book"
						activate
						set validate fonts before installing to false
						tell application "System Events" to tell process "Font Book"
							keystroke "," using command down
							repeat until exists window "Font Book Preferences"
								delay 0.5
							end repeat
							tell window "Font Book Preferences" to set installPath to value of pop up button 1 -- check the installation location
							delay 0.5
						end tell
						close window 1
						if installPath is "User" then
							set installPath to (path to fonts from user domain)
						else
							set installPath to (path to fonts from local domain)
						end if
						repeat with aFont in theFonts
							set temp to aFont's name as string
							if "Times" is not in temp then -- Don't allow times to be replaced!
								if kind of (info for aFont as alias) does not contain "outline font" then
									open aFont
									if exists window "Font Validation" then
										close window "Font Validation"
									else
										set x to 0
										repeat until exists window 3
											delay 0.5
											set x to x + 1
											if x > 30 then exit repeat
										end repeat
										repeat while (count windows) > 2 -- if there are multiple fonts in the suitcase
											try
												tell application "System Events" to tell process "Font Book"
													click button 1 of group 1 of window 1 --(get some window whose images is not {})
												end tell
											on error
												try
													tell application "Finder" to move aFont to trash
												end try
											end try
											
										end repeat
										
										set NewFontInstalled to true
										try
											tell application "Finder" to move aFont to trash
										end try
									end if
								else
									do shell script "mv -f " & quoted form of POSIX path of (aFont as alias) & space & quoted form of POSIX path of installPath
									try
										tell application "Finder" to move aFont to trash
									end try
									set NewFontInstalled to true
								end if
							else
								try
									tell application "Finder" to move aFont to trash
								end try
							end if
						end repeat
					end tell
				on error TheError number errNum
					if errNum = -2763 then
						--set ErrorMessage to ErrorMessage & "It appears that a Font we have been sent is corrupt." & return
						if SpeakTheErrors then say "[[rate " & TheSpeechRate & "]]It appears that a Font we have been sent is corrupt." using TheVoice
					end if
					if errNum ≠ -2763 then display dialog "SecondAttachmentPrintCycle " & return & "Error number " & errNum & return & TheError as string giving up after 4
				end try
				
			end if
		end try
		try
			quit application "Font Book"
		end try
	end tell

Model: intel 24" iMac
Browser: Safari 525.20
Operating System: Mac OS X (10.5)