Using standard AppleScript. Does the job but may be slow when the table is large.
tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1
set n to 1
tell column 3
repeat with i from 1 to count rows
set value of cell i to n
set n to n + 1
Using GUI scripting. I know that some users dislike it but it’s hugely faster for large tables.
tell application "Numbers"
set row_loc to localized string "ROW" from table "TSCalculationEngine"
set autofillCell_loc to localized string "Autofill Cells" from table "TSTables"
tell document 1 to tell sheet 1 to tell table 1
set firstRow to 5 -- of course you may replace by 1
tell column 3
set value of cell firstRow to "=" & row_loc & "() -" & firstRow & "+1"
set theRange to (name of cell firstRow & ":" & name of cell -1)
set selection range to range theRange
tell application id "com.apple.systemevents" to tell process "Numbers"
set frontmost to true
tell menu bar 1 to tell menu bar item 6 to tell menu 1 to tell menu item autofillCell_loc to tell menu 1 to click menu item 3
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 3 avril 2020 13:53:22
It’s better not to use AppleScript here. Better to do everything manually in the Numbers.app, using the concept of “formula”:
set the value of the 1st cell of the column, for example = number 1
set in the 2nd cell of the column instead of the number the formula =A1+1 (Insert → Formula → Custom Formula …)
copy the contents of the 2nd cell (right mouse click + Copy).
select all the other cells in the column and paste the copied one (right click + Paste).
Your automated Numbers’s document is ready. Now, if you change the value of any cell, Numbers will automatically increase the values of all subsequent ones and very quickly. You can save this automated document and use forever.
No AppleScript is needed here. AppleScript makes sense when you need to automate something that is not yet automated…
Of course, you can automate 4 steps described above using AppleScript, but I think something you do only once, no need the automation.
It’s right if this task is the only one to achieve but my understanding, given the other question asked by the same OP, is that it’s just one of a flow of tasks whose one of them is the creation of a new document from scratch exactly as I do quite every day.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 3 avril 2020 16:07:16