I have an AppleScript to archive a message in Outlook 2016 for Mac. Please see below. On Outlook 2016 for Mac 16.13 (released in May 2018 via Insider Slow channel), the script fails for messages in newly added Gmail accounts when it tries to get the account of the selected message/folder (curAccount is missing value after set curAccount to account of curFolder).
This version of Outlook added support Google Calendars and Contacts and you need to remove and add Gmail account in order to get this feature. The script works fine for Exchange/Office365 accounts as well as for Gmail accounts added before the upgrade to 16.13. It fails only for newly added Gmail accounts. I guess, the Gmail integration is done differently now in this new release of Outlook 2016 for Mac.
Do you know a work-around for this issue? Do you have a script example to get a folder handle in Gmail account?
AppleScript
tell application "Microsoft Outlook"
set currMsgs to current messages
-- Check to make sure items are selected, if not then quit
if (count of currMsgs) is 0 then
display notification "No message selected" with title "Microsoft Outlook" subtitle "Move to Archive"
return
end if
-- Iterate through selected items
repeat with msg in currMsgs
set curFolder to folder of msg
set curAccount to account of curFolder
if curAccount is missing value then
display dialog ("An error occurred and the messages were not moved " & name of curFolder & " . Done") buttons {"Quit Script"} default button 1 with icon stop
return
end if
set destFolder to folder "Archived" of curAccount
move msg to destFolder
end repeat
-- 1 Notification...
if (count of currMsgs) is 1 then
display notification "One message moved to " & name of curAccount & ":" & name of destFolder with title "Microsoft Outlook" subtitle "Move to Archive"
end if
-- Multi Notification...
if (count of currMsgs) > 1 then
display notification "" & (count of currMsgs) & " messages moved to " & name of destFolder with title "Microsoft Outlook" subtitle "Move to Archive"
end if
end tell