I need to check if an email is selected and not a mailbox in Outlook.
tell application "Microsoft Outlook"
set selectedMessages to selection
if selectedMessages is missing value or selectedMessages is mail folder then
display dialog "Please select an email first!"
return
end if
end tell
If a mailbox is selected then I should see the dialog. Instead nothing is shown. What am I doing wrong? This is old Outlook where AppleScript works fine.
if selectedMessages is missing value or class of selectedMessages is mail folder then
If we isolate the second part of your compound if statement and then run the script with either a message or mail folder selected, you get the following results:
-- if message is selected
set selectedMessages to selection
get class of selectedMessages
-- Log history
get selection
--> outgoing message id 1
get class of outgoing message id 1
--> outgoing message
-- if mailbox is selected
set selectedMessages to selection
get class of selectedMessages
-- Log history
get selection
--> mail folder id 4
get class of mail folder id 4
--> mail folder
Note that when a mail folder is selected, getting the selection returns a ‘mail folder id’, which doesn’t satisfy your condition. NB I’m using outlook 2011.