I tried all the permission tricks I know form the past but for some reason I cannot get this to work again.
here is the script:
tell application "Microsoft Outlook" to activate
-- bring it to the front
tell application "System Events"
tell application process "Microsoft Outlook"
set frontmost to true
end tell
end tell
--run send and receive
tell application "System Events"
tell application "Microsoft Outlook" to activate
tell application "Microsoft Outlook"
if it is running then
activate
end if
tell application "System Events"
keystroke (ASCII character 107) using control down & command down
end tell
end tell
end tell
-- go to the Desktop were Outlook runs
repeat 2 times
tell application "System Events" to key code 123 using control down
end repeat
tell application "Microsoft Outlook" to activate
tell application "System Events"
set frontmost of application process "Microsoft Outlook" to true
repeat until application process "Microsoft Outlook" is frontmost
delay 0.1
end repeat
tell application process "Microsoft Outlook"
keystroke "k" using {control down, command down}
end tell
end tell
You need to grant access in System Preferences/Security & Privacy/Privacy/Accessibility, Input Monitoring, Full Disk Access, etc… to allow Microsoft Outlook, System Events, and your AppleScript Applet to be able to control your computer.
System Events is located here…. /System/Library/CoreServices/System Events.app
OK Solved it. Running it in Automator as an App works like this.
on run {input, parameters}
tell application "Microsoft Outlook" to activate
tell application "System Events"
set frontmost of application process "Microsoft Outlook" to true
repeat until application process "Microsoft Outlook" is frontmost
delay 0.1
end repeat
tell application process "Microsoft Outlook"
click menu item "Send & Receive" of menu 8 of menu bar 1
end tell
end tell
return input
end run