0

I would like to block a spammer's address using AppleScript.

With the Inbox message selected, I execute this script:

tell application "System Events"

    click menu item "Block Sender" in menu item "Junk Mail" in menu bar item "Message" in menu bar 1 of application process "Microsoft Outlook"

end tell

Which results in this error:

System Events got an error: Can’t get menu item "Junk Mail" of menu bar item "Message" of menu bar 1 of application process "Microsoft Outlook".

The Junk Mail menu has a submenu:

enter image description here

The AppleScript Editor has been granted access to control my computer:

enter image description here

What am I missing?

craig
  • 25,664
  • 27
  • 119
  • 205

1 Answers1

0

I can't really test it with Outlook, but you missed to tell the menus "Message" and "Junk Mail" of the menu items:

tell application "System Events"

    click menu item ¬
         "Block Sender" in menu ¬
         "Junk Mail" in menu item ¬
         "Junk Mail" in menu ¬
         "Message" in menu bar item ¬
         "Message" in menu bar 1 ¬
         of application process "Microsoft Outlook"

end tell
Ken Williams
  • 22,756
  • 10
  • 85
  • 147
user309603
  • 1,518
  • 11
  • 10
  • This does run without producing an error, but it doesn't actually seem to add the sender to the Blocked Senders list. – Ken Williams Nov 05 '19 at 18:58
  • You may need to add `tell application "Microsoft Outlook" to activate` before you first `tell` – craig Sep 06 '22 at 17:29