Navigating the cumbersome UI of Numbers app can be a drag... KM is helping me A LOT to minimize this effect.
One example is formatting dates - I like to see the dates in Brazilian format = dd/mm/yy - no time shown. Frequently, when importing from Excel, the date comes up in american format = mm/dd/yyyy with time showm.
To change this is an avalanche of clicks - format/cell/automatic/date and time/date, and then select desired format - if you're not dead yet... and another bunch of clicks to remove the time stamp.
Since most of this UI elements can be only reached by clicks, the macro I wrote is replete of mouse clicking actions, with all its perils and dangers. So here is the point:
is there a script that could directly select the desired format, without all these tedious clicks, macro or not?
You can play around with click at found image and such like, but this sort of thing is where AppleScript excels.
This macro is a working example of selecting a specific range.
It also contains code to select a specific column or row.
The meat of the script looks like this:
tell application "Numbers"
if document 1 exists then
tell document 1 to tell active sheet
set theTables to every table
tell table 1
# set the selection range to column "B" --> Column
# set the selection range to row "1" --> Row
set selection range to range "A1:B17" --> Range
end tell
end tell
end if
end tell
See the commented-out lines? They're how you select a column or row.
All the extra code in the script is to allow you to run the script again to make your selection in the next table if there is one.
Do you have any ideas on the formatting? I found the script below, but it is limited - you cannot give the date, number or percent the desired format, like setting number of decimals, thousands separator, sequence of day, month, year, etc.
tell application "Numbers"
set the Formats to {text, currency, date and time, number, percent}
tell table 1 of sheet 1 of document 1
set format of cell "D10" to item 4 of Formats -- set the format of the first cell to currency
end tell
end tell
I think I found a way to format the decimals and thousand separator - follows:
tell application "Numbers"
activate
tell front document's active sheet
tell (first table whose class of selection range is range)
set the selectionRange to the selection range
tell application "System Events" to keystroke "c" using {command down}
end tell
set format of selectionRange to automatic
set value of cells of selectionRange to "(0.000.000,00)" -- the desired format
set format of selectionRange to number
tell application "System Events" to keystroke "v" using {command down, shift down, option down}
end tell
end tell