1
votes

This works in the AppleScript Editor:

tell application "Microsoft Outlook" to activate
tell application "System Events"
  click menu item "Block Sender" of menu "Junk Mail" of menu item "Junk Mail" of menu "Message" of menu bar item "Message" in menu bar 1 of process "Outlook"
end tell

However, when I move this script to Outlook's script folder (~/Library/Application Support/Microsoft/Office/Outlook Script Menu Items/) and attempt to run it from Outlook's script menu, I get an error:

System Events got an error: Can't get menu bar 1 of process "Outlook". Invalid index.

Should I not be using System Events?

1
Is the process really named "Outlook"? In your other question you wrote application process "Microsoft Outlook".user309603
I've used "Outlook" and "Microsoft Outlook". Both have the same effects in both contexts.craig
It's actually the wrong error, but has Outlook access to control your computer?user309603
No, it isn't listed in the 'Privacy' section of the Accessibility section of the Security & Privacy System Preference.craig
I'm pretty sure it has to. Drag Outlook to the list.user309603

1 Answers

2
votes

There's a bug in Outlook now that Outlook plugin scripts can't access the menu bar in UI scripting, even if Outlook is added to the Security list of apps that can control your computer. You have two workaround options.

  1. Save your script in system-wide script menu at /Library/Scripts/ in which case you'll first be prompted with "osascript is not allowed assistive access". You need to go to System Preferences/Security & Privacy/Privacy/Accessibility and enable SystemUIServer Then, that script will run from that system-wide menu instead of Outlook's script menu.

  2. You could set a keyboard combo to the "Block Sender" menu item using System Preferences/Keyboard/Shortcuts. You could then just use that key combo yourself, or if you still need to do through a script, the script can call that key combo using UI scripting. enter image description hereenter image description here