Timeout error occurs with display dialog in repeat loop. Any ideas?

Folks,

I’ve got this snippet in a script

		-- Loop through each work number and identify the image numbers associated with it.
		repeat with workIndex from 1 to workNumberCount
			set workNumber to item workIndex of workNumberList
			set imageNumberList to {} as list
			--open irisDirectory & irisWSLinks with password irisPassword
			getURL irisRemoteLocation & irisWSLinks
			set irisWSLinksDB to (a reference to database irisWSLinks)
			if (exists irisWSLinksDB) is false then
				display dialog "There is a problem finding the " & irisWSLinks & " file. Click Cancel and resolve this, then run the script again."
				return
			end if
			tell database irisWSLinks
				set imageList to (ID of every record whose (cellValue of cell "Work No." = workNumber)) as list
				set imageCount to count of imageList
				if (imageCount > 0) then
					set imageNumberList to {} as list
					repeat with wsIndex from 1 to imageCount
						try
							set wslinkRecord to (a reference to record ID (item wsIndex of imageList as integer))
							set imageNumber to cellValue of cell "Surrogate No." of wslinkRecord
							set imageNumberList to imageNumberList & imageNumber as list
						on error
							my write_to_file((outputDirectory & outputStatisticsFilename), "WARNING: Work number " & workNumber & " has problems accessing its image numbers." & newLine, true)
						end try
					end repeat
				else
					my write_to_file((outputDirectory & outputStatisticsFilename), "WARNING: Work number " & workNumber & " does not have any associated images." & newLine, true)
				end if
			end tell
			set imageCount to count of imageNumberList
			if (imageCount > 0) then
				tell database irisSurrogat
					repeat with imageIndex from 1 to imageCount
						display dialog "Processing image record " & imageIndex & " of " & imageCount & " for work record " & workIndex & " of " & workNumberCount buttons {"OK"} default button "OK" giving up after 1
						set imgNum to item imageIndex of imageNumberList
						set cell "Surrogate No." of request 1 to imgNum
						find window 1
						if ((cellValue of cell "Surrogate No." of current record) = imgNum) then
							set imageNumber to cellValue of cell "Surrogate No." of current record
							set imageType to cellValue of cell "Source::Image Type" of current record
							set imageApproved to cellValue of cell "Approved" of current record
							set digitalMedia to my getDigitalFile(imageNumber) as list
							set imageDigitalFilename to item 1 of digitalMedia as text
							set imageColor to cellValue of cell "Color" of current record as text
							set imageViewType to cellValue of cell "View Type" of current record as list
							set imageViewDescription to cellValue of cell "View Description" of current record as text
							set imageViewDate to cellValue of cell "View Date" of current record as text
							set imageSubjects to cellValue of cell "Subjects" of current record as list
							set imageSubjectAuthority to my getSubjectAuthority(imageSubjects) as list
							set imageSubjectSubtypes to cellValue of cell "Subject Subtypes" of current record as list
							set imageSubtypeAuthority to my getSubjectAuthority(imageSubjectSubtypes) as list
							set imagePID to cellValue of cell "PID" of current record as text
							set imageSourceNumber to cellValue of cell "Source No." of current record
							set imageProjectName to cellValue of cell "Project Name" of current record as text
							set imageExportDate to cellValue of cell "Export Date" of current record
							set imageMetadataString to imageNumber & fieldSeparator & imagePID & fieldSeparator & imageProjectName & fieldSeparator & imageDigitalFilename & fieldSeparator & imageColor & fieldSeparator & my joinby(imageViewType, valueSeparator) & fieldSeparator & imageViewDescription & fieldSeparator & imageViewDate & fieldSeparator & my joinby(imageSubjects, valueSeparator) & fieldSeparator & my joinby(imageSubjectAuthority, valueSeparator) & fieldSeparator & my joinby(imageSubjectSubtypes, valueSeparator) & fieldSeparator & my joinby(imageSubtypeAuthority, valueSeparator) & fieldSeparator & imageExportDate & fieldSeparator & imageSourceNumber as text
						else
							set imageApproved to "" as text
							set imageType to "" as text
							set imageDigitalFilename to "" as text
							set imageSourceNumber to "" as text
							set imageProjectName to "" as text
							set imageMetadataString to "" as text
						end if
						-- Only export images that have been approved.
						if (imageApproved ≠ "") then
							-- and only work with slide or digital image type records
							if (imageType = "slide") or (imageType = "digital image") then
								if (imageDigitalFilename ≠ "") then
									set sourceMetadataString to my getSourceInformation(imageSourceNumber) as text
									-- Write out the image information with the current work data.
									set metadataLine to workNumber & fieldSeparator & projectName & fieldSeparator & imageMetadataString & fieldSeparator & sourceMetadataString & newLine as text
									my write_to_file((outputDirectory & outputFilename), metadataLine, true)
									set exportedImageCount to exportedImageCount + 1
									-- Mark the image record to indicate that it is being exported for GDMS.
									set cellValue of cell "Export Date" of current record to exportDate
									-- Determine if this image is a new one based on the project name
									if (imageProjectName = projectName) then
										set projectImageCount to projectImageCount + 1
									end if
								end if
							end if
						end if
					end repeat
				end tell
			else
				display dialog "Processing no image records for work record " & workIndex & " of " & workNumberCount buttons {"OK"} default button "OK" giving up after 1
			end if
		end repeat

When it runs, it always fails at the same line but not necessary the same record in the FileMaker db:

display dialog "Processing image record " & imageIndex & " of " & imageCount & " for work record " & workIndex & " of " & workNumberCount buttons {"OK"} default button "OK" giving up after 1

The error returned is “AppleEvent timed out.” I don’t understand why it times out since I have the display dialog command give up after 1 second. I’ve added the display dialog so that the user can see the progress of the data.

In addition, the entire tell application block of code is within a

with timeout of 600 seconds

statement.

I’m curious to know if anyone else has had issues with using display dialog in nested repeat loops.

Thanks,
Jack

jackinva,

It’s hard to say where the error is occuring in your code. The line that is highlighted is not necessarily where the error is. (Just a thought here: have you tried upping the “giving up after” time to maybe 5 just to see if there might be a problem with the amount of info to be in the dialog. Maybe more time is necessary for the info to be put into the dialog before it has already told itself to quit. I don’t know if this has ever been an issue or not.) You have a couple of calls to subroutines that are not included in your code. There could be a problem there. I also find it useful to comment out the try statements from time to time so I can see if a problem is within them. In as far as your timeout block, you could use 6000 seconds. How long does it take before a timeout error occurs?

I hope this gives some ideas.

PreTech

Thanks for the suggestions PreTech. I might up the 600 to 6000. I don’t know how long the script runs before it fails with the display dialog command. I’d guess between 15 and 30 minutes. I thought that with timeout code did not imply how long the script ran, but rather how long it would wait before timing out when executing an application command? I added it since this script is accessing a database across the network.

I should clarify that I know the problem is the display dialog command from my attempts at debugging the issue. If that command is commented out, the script runs fine with no problems. I hesitate to up the giving up time as the intention of the display dialog is simply to function like a “progress bar” for the user (since I could not find such a feature available in AppleScript) when she checks on the progress of it (running on another computer in another room).

At this point, management thinks we might drop the “progress bar” idea. But I was very interested in finding out if anyone else has had similar problems such that this might be an undocumented bug of some sort.

Thanks,
Jack

P.S. I purposely did not include all my code (i.e. the functions) so as to keep the original posting from being extremely large. My apologies if it made it more difficult to provide any assistance.

jackinva, you may be able to work these into your project:

BP Progress Bar (by Me)
My Progress Bar (by kiwilegal)

Bruce,

Thanks for the info. I will definitely check them out! - Jack

Bruce,

I wanted to check out your progress bar but get ‘corrupt image when trying to open this file’ after downloading. I noticed someone else had this problem and wrote it at as a review under the download back in January… might this just be a few occassions of it not mounting correctly? Has it been working for most people?

Thx, Brad.

Jack,

I was suggesting the timeout go from 600 to 6000 just in case some part of what your script is doing is taking longer than the 10 minutes you currently allow to complete. As far as I know, you are correct with what the timeout does.

PreTech

Just a quick blind suggestion…

jackinva wrote:

The whole script should be within this statement… and if it’s taking 20-30 minutes to execute, the timeout should be well in excess of that.

(Just wasn’t clear whether the ‘tell app’ block was the whole shebang or not.)

Peter B.


Hey Peter,

Really? I do have variable initialization, function definitions, and code that reads a text file (to identify which records in the FileMaker database to select) outside of the with timeout block. All of that should go inside it?

Thanks,
Jack

To be honest, once again I may have butted in when I have insufficient knowledge to comment.

I tend to build simple ‘in line’ scripts, so about the only items outside a ‘with timeout’ are property statements.

However, it’s easy enough to try… (and reverse, if it simply doesn’t work).

I’ll be curious.

Peter B.