How do I select non contiguous Numbers spreadsheet cells using applescript? The AppleScript Numbers dictionary has info on single cells, and a range of cells.
I’d like to specify individual, non-contiguous cells.
My example works, but repeating lines like this bugs me.
Is there a simple, more elegant/efficient solution?
Can the cell names/numbers go in a list? What would the syntax be?
These all give various errors:
set the background color of cell &quot;A1&quot; and &quot;A5&quot; to cellColour 
set the background color of cell &quot;A1&quot; &amp; &quot;A5&quot; to cellColour 
set the background color of cell {“A1”, &quot;A5”} to cellColour 
set the background color of cell {“A1:A5”} to cellColour
set the background color of cell {A1:A5} to cellColour
set the background color of cell (A1,A5) to cellColour
set the background color of cells {A1,A5} to cellColour

My script:
-- Opens a Numbers spreadsheet, then sets non contiguous cells' background colour
set cellColour to {0, 0, 0}

tell application &quot;Numbers&quot;
   activate
     if not (exists document 1) then make new document
       tell the front document
         tell active sheet
           set thisTable to ¬
               make new table with properties ¬
                  {row count:5, column count:3}
           tell thisTable
                set the width of every column to 30
                set the height of every row to 30
                -- make all cells white first
                repeat with i from 1 to the count of cells
                  set the background color of cell i to {65535, 65535, 65535}
                end repeat
                set the background color of cell &quot;A1&quot; to cellColour
                set the background color of cell &quot;A5&quot; to cellColour
                set the background color of cell &quot;B2&quot; to cellColour
                set the background color of cell &quot;C4&quot; to cellColour
           end tell
        end tell
    end tell
end tell

Thanks in advance :-)
Try the following:
set thisColor to {32767, 32766, 32767}
set theseCells to {&quot;A1&quot;, &quot;A5&quot;, &quot;B2&quot;, &quot;C4&quot;}

tell application &quot;Numbers&quot;
    activate
    if not (exists document 1) then make new document
    tell the active sheet of the front document to set thisTable to ¬
        make new table with properties {row count:5, column count:3}
    tell thisTable
        set the width of its columns to 30
        set the height of its rows to 30
        set the background color of its cells to {65535, 65535, 65535}
        repeat with aCell in theseCells
            set the background color of cell aCell to thisColor
        end repeat
    end tell
end tell