Mac – Help with AppleScript to automate Numbers Cell Formatting

applescriptautomatoriworkmacnumbers

I do several mundane repetitive tasks using Numbers App on a Mac, and wish I could just automate the same with the help of AppleScript.

I got Numbers Spreadsheet with several tables, on the selected table, I want the script to run through all rows of selected column (which is column 1 mostly) and format cells (color the text blue or red) depending on even or odd value condition.

thanks

Best Answer

I finally got what I wanted. I used an app called Script Debugger 7, though not necessary, it really helped me with all the classes & options available with each application and detailed help.

Further, it was really easy to write scripts in this app. For anybody needing a similar solution, I hope this helps. This script is not the best, in terms of error checking or dynamic names, but that's for another day.

------Script below--------

property rBlue : {1721, 15020, 27788}
property rPink : {48626, 3448, 26715}

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions


tell application "Numbers"
tell document 1
    tell active sheet
        tell table "Table 1"
            set rCount to get row count

            repeat with r from 2 to rCount
                set valCell to formatted value of cell ("A" & r)
                set remCell to valCell mod 2

                if remCell = 0 then set text color of cell ("A" & r) to rBlue
                if remCell ≥ 1 then set text color of cell ("A" & r) to rPink
            end repeat

        end tell
    end tell
end tell

end tell