Search code examples
macosterminalnumbersapplescriptaccessibility

AppleScript: "System Events" from Terminal not working


TASK: I'm using AppleScript to open a Numbers file and hide a column. After selecting the column that I want to hide I'm using "System Events" to go in the Numbers menu and hide the column.

ISSUE: When I launch the script from the AS Editor the script works but when I launch the same script from terminal using osascript the "System Events" portion of the script doesn't work (the column is selected but doesn't get hidden).

WHAT I TRIED: In Settings -> Privacy and Security -> Automation: the Terminal App has both Numbers and System Events enabled In Settings -> Privacy and Security -> Accessibility: the Terminal App is enabled.

Here is the code (the System Events portion)

tell application "System Events"
    tell process "Numbers"
        click menu item "Hide Column" of menu 1 of menu bar item "Table" of menu bar 1
    end tell
end tell

Solution

  • My "System Events" call was enveloped by "ignoring application responses - end ignoring".

    The actual code was:

    ignoring application responses
        tell application "System Events"
            tell process "Numbers"
                click menu item "Hide Column" of menu 1 of menu bar item "Table" of menu bar 1
            end tell
        end tell
    end ignoring
    

    The part within the "ignoring" is actually ignored when running the code through terminal, while it works if running through Script Editor.