Little bug in Outlook - Filter Mailboxes script

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

Thanks for the report, however I am not seeing that problem here, and no one else has reported problems with this. Which version of macOS are you using? Does the problem occur after restarting your Mac? What about if you run this script?

tell application "Microsoft Outlook"
    set _startDate to current date
end tell

I’m using Sierra 10.12.3.
I’m not and expert of AppleScript, but I found this explanation about the error number -10004: Error -10004 is an Apple Event Privilege Error. From the 10.6 AppleScript Release Notes: “For security reasons, most scripting addition commands now return a “privilege violation” error when sent between application processes.” The say (or current date) command is from “Standard Additions” (a scripting addition), so it should either not be used in an application tell statement, or prefixed with a tell me or tell current application so that you are not targeting the application.
If I run your script, I get the -10004 error.

How are you running the script?

From the script editor

Me, too. It’s a mystery to me why we are seeing different results. But it sounds like you know how to update the script, and I will update the official one.

Yes, you just have to “limit” the tell block excluding the calculation of the duration.

This has been incorporated into the latest version of the script.