0

I am trying to run a very simple apple script from VBA. The VBA code is:

NavigationJunk = AppleScriptTask("Budget Report Apple Scripts/NavigationMoveWindowsAppleScript.scpt", "NavigationMoveWindowLeftHandler", "") 

The script reads:

on NavigationMoveWindowLeftHandler(Junk)
     tell application "System Events" to key code 123 using {option down, control down}
end NavigationMoveWindowLeftHandler

where the complete path for the .scpt is: "/Users/Andrew/Library/Application Scripts/com.microsoft.Excel/Budget Report Apple Scripts/NavigationMoveWindowsAppleScript.scpt" (this is the correct path as documented here: Apple Script Task Throwing an Error 5

This code simply performs the key stroke cntrl+option+left arrow. That key stroke is a shortcut for the app Magnet to move the window to be half screen left.

This worked prior to updating my system to MacOS Ventura. I attempted to restart, uninstall Excel, reset the permissions in System Settings/Privacy/Automation (as documented here: Reset MacOS Privacy Settings) and reinstall Excel. When I tried to run the VBA code I was prompted to grant permission to system events and still received an invalid procedure error. I verified that when I call the handler from within the Apple Script Editor the system performs the keystrokes with no issues. I assume this is some sort of permission thing...How do I fix this?

Of note: this code called prior to the AppleScriptTask above runs just fine:

AppleScriptResult = Split(AppleScriptTask("Budget Report Apple Scripts/NavigationMoveWindowsAppleScript.scpt", "NavigationGetScreenResolution", ""), " ")

This is curious because the .scpt is the same file and calls a different handler:

on NavigationGetScreenResolution(Junk)
    return do shell script "system_profiler SPDisplaysDataType | grep Resolution"
end NavigationGetScreenResolution

and runs just fine. Any help here would be greatly appreciated

Andrew
  • 21
  • 1
  • One more thing, I just commented the one line "tell application "System Events" to key code 123 using {option down, control down}" in the .scpt and my code ran to completion so that does seem to confirm that the system doesn't like Excel calling to system events in particular. – Andrew Feb 16 '23 at 03:34

0 Answers0