This one’s way over my head.
When trying to open the unopenable .rtfd that used to freeze my app, (that Shane said ‘use ignoring application responses on), an error (-2763) is being generated that is unstoppable.
The error does not get trapped by the first ‘on error’ trap, but instead propagates backwards to the preceding error trap, which then errors without waiting, which then propagates backwards again, ad infinitum, until the originating mail processing handler is reach, which then tried to open the mail item again, and so repeats the loop forever. Lots of error dialog boxes on screen.
on fileAndMailHandlingSubRoutine2()
if my runForOz then say "pasting into r t f d" without waiting until completion
try
tell application "TextEdit" to close every document
try
ignoring application responses
tell application "TextEdit"
try
# This tries to open the .rtfd that is unopenable
open my theDesktoprtfdFile as alias
# This is ignored if file is unopenable
on error errmsg number errnum
my transferMessage("* items to manually process")
try
tell application "Finder" to move file (my theDesktoprtfdFile) to trash
end try
my setEMsgs(errnum, "mainMessagesView", "Error in fileAndMailHandlingSubRoutine1 whilst opening rtfd document with TextEdit. Error number " & errnum & " Error " & errmsg as text, "Error Message Orange", true, "Cochin Bold", "14")
my writeTheErrors()
return
end try
end tell
end ignoring
end try
# This ‘second backwards’ trap works
on error errmsg number errnum
if errnum = -2763 then
try
my doEventFetch()
#
# In case dialog still open
#
tell application "TextEdit"
tell application "System Events" to tell process "TextEdit"
try
click button "OK" of window 1
end try
end tell
end tell
if my runForOz then tell application "System Events" to display dialog "this is a fileAndMailHandlingSubRoutine2 error -2763" as text giving up after 10
try
tell application "Mail" to set temp to (message id of my currentMailItem) as rich text
if my runForOz then tell application "System Events" to display dialog temp & return & (count of temp) & return & my mailBoxProcessName as text giving up after 20
try
if (count of temp) is 0 then
if my runForOz then say "trying" as text without waiting until completion
tell application "Mail" to quit
tell application "Finder"
repeat while exists process "Mail"
do shell script "sleep 0.1"
end repeat
end tell
tell application "Mail"
set tempstore to messages of mailbox (my mailBoxProcessName) as list
end tell
set my currentMailItem to item 1 of tempstore
if my runForOz then say "current mail item reset" without waiting until completion
tell application "Mail" to set temp to (message id of my currentMailItem) as rich text
if my runForOz then tell application "System Events" to display dialog temp & return & (count of temp) & return & my mailBoxProcessName as text giving up after 20
set my attachmentMailFlag to false
# Creates a loop
my transferMessage("* items to manually process”)
try
tell application "Finder" to move file (my theDesktoprtfdFile) to trash
end try
my setEMsgs(errnum, "mainMessagesView", "Error in fileAndMailHandlingSubRoutine1 whilst opening rtfd document with TextEdit. Error number " & errnum & " Error " & errmsg as text, "Error Message Orange", true, "Cochin Bold", "14")
my writeTheErrors()
return
end if
end try
if my runForOz then say "tried" as text without waiting until completion
end try
end try
end if
end try
# [ Removed Code]
on transferMessage(tempMailbox)
set my theNewMailbox to tempMailbox
# [ Removed Code]
try
# tell application "Mail"
set p to 10
move my currentMailItem to mailbox(my theNewMailbox)
# end tell
on error errmsg number errnum
# errnum = -2763 is error that was genererated by trying to open unopenable file
if errnum = -2763 then
# this runs in a continuous loop even after quitting Mail app
if my runForOz then say "this is a mailbox error -2763, p = " & p
else
try
if my runForOz then tell application "System Events" to display dialog "MainProcessingLoops's last transferMessage " & errmsg & " number is " & errnum & " p = " & p as text giving up after 20
end try
try
if errnum is not in {8, -1728, -10006, -1700} then my setEMsgs(errnum, "mainMessagesView", "Major Error: transferMessage Error " & errmsg & " p = " & p as text, "Error Message Orange", true, "Cochin Bold", "14")
end try
end if
end try
end transferMessage