MacOS – How to unhide columns in Numbers using AppleScript

applescriptmacosnumbers

How do I unhide columns in Numbers using AppleScript? I created a custom shortcut so that +U unhides all columns, so I have tried this so far:

tell application "Numbers"
    open POSIX file "/path/to/file"
    tell document "file"
        set active sheet to sheet "sheet"
        tell table "table" of sheet "sheet"
            set selection range to range "A1"
            tell application "System Events" to keystroke "U" using command down
        end tell
    end tell
end tell

I get no error message, but the columns are still hidden.

I am using the latest version of MacOS, AppleScript, and Numbers.

Best Answer

I figured it out. As user3439894 said, there was a conflict between the shortcuts for underlining and unhiding columns. I changed it to +U.

I needed to activate the window before shortcuts could be used on it.

tell application "Numbers"
    activate
    open POSIX file "/path/to/file"
    tell document "file"
        set active sheet to sheet "sheet"
        tell table "table" of sheet "sheet"
            set selection range to range "A1"
            tell application "System Events" to keystroke "u" using command down
        end tell
    end tell
end tell