Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the number of decimals in a Numbers cell using AppleScript?

I can set the format of a cell in a Numbers spreadsheet using:

tell application "Numbers"
    activate
    tell document 1
        tell active sheet
            set the selectedTable to ¬
                (the first table whose class of selection range is range)
        end tell
        tell selectedTable
            tell column "J"
                set the format of cell 3 to number
            end tell
        end tell
    end tell
end tell

But how do I set the number of decimal places of the cell?

like image 406
Daryl Spitzer Avatar asked Jun 29 '16 04:06

Daryl Spitzer


1 Answers

Unfortunately the AppleScript dictionary of Numbers does not support to set the decimal places, however you can do it with GUI scripting.

Since GUI scripting strongly depends on the software version, this is for Numbers 3.6.2

tell application "Numbers"
    activate
    tell document 1
        tell active sheet
            set the selectedTable to ¬
                (the first table whose class of selection range is range)
        end tell
        tell selectedTable
            tell column "J"
                set the format of cell 3 to number
            end tell
        end tell
    end tell
end tell

tell application "System Events"
    tell process "Numbers"
        tell radio group 1 of window 1
            if value of radio button "Cell" is 0 then
                click radio button "Cell"
                repeat until value of radio button "Cell" is 1
                    delay 0.2
                end repeat
            end if
        end tell
        tell text field 1 of scroll area 4 of window 1
            set value of attribute "AXFocused" to true
            set value to "2"
            keystroke return
        end tell
    end tell
end tell

In a system language other than English the literal string Cell might be localized.

like image 95
vadian Avatar answered Sep 30 '22 18:09

vadian