It seems that if you call current date in a tell block, you obtain a -10004 error.
So, you could change the script from this:
on unreadMessagesFromMailbox(_mailbox)
**tell application "Microsoft Outlook"**
set _startDate to current date
try
with timeout of 2 * 60 seconds
set _messages to messages of _mailbox whose is read is false
end timeout
on error _error number _errorNumber
my logToConsole("Outlook reported error “" & _error & "” (number " & _errorNumber & ") getting the messages from " & my locationFromMailbox(_mailbox))
return {}
end try
set _endDate to current date
set _duration to _endDate - _startDate
set _statusMessage to "Outlook took " & _duration & " seconds to get " & (count of _messages) & " unread messages from " & my locationFromMailbox(_mailbox)
if _duration > 5 then
my logToConsole(_statusMessage)
else
my debugLog(_statusMessage)
end if
return _messages
**end tell**
end unreadMessagesFromMailbox
to this:
on unreadMessagesFromMailbox(_mailbox)
set _startDate to current date
**tell application "Microsoft Outlook"**
try
with timeout of 2 * 60 seconds
set _messages to messages of _mailbox whose is read is false
end timeout
on error _error number _errorNumber
my logToConsole("Outlook reported error “" & _error & "” (number " & _errorNumber & ") getting the messages from " & my locationFromMailbox(_mailbox))
return {}
end try
**end tell**
set _endDate to current date
set _duration to _endDate - _startDate
set _statusMessage to "Outlook took " & _duration & " seconds to get " & (count of _messages) & " unread messages from " & my locationFromMailbox(_mailbox)
if _duration > 5 then
my logToConsole(_statusMessage)
else
my debugLog(_statusMessage)
end if
return _messages
end unreadMessagesFromMailbox