First, here's a slightly improved version of my previous script:
set myInvoices to alias "Macintosh HD:Users:username:Desktop:My invoices.numbers"
tell application "Numbers"
launch
activate
set thisDocument to openmyInvoices
-- Copy the tables of sheet 1:
tell thisDocument to set active sheet to sheet 1 -- sheet 1 is used as a template for the other sheets
tell application "System Events" to tell process "Numbers"
keystroke "a" using {command down} -- select all
keystroke "c" using {command down} -- copy
keystroke "a" using {shift down, command down} -- unselect all
end tell
-- Get the number of the next invoice (one sheet per invoice):
set N to (countsheets of thisDocument)
set theInvoiceNumberAsText to "Invoice #" & text 1 through (5 - (countN as text)) of "00000" & N
-- Make a new sheet:
tell thisDocument to set active sheet to sheetN
tell thisDocument to makenewsheetwith properties {name:theInvoiceNumberAsText}
set theNewSheet to result
-- Replace the default table with the tables of sheet 1:
deletetable 1 of theNewSheet
tell application "System Events" to keystroke "v" using {command down} -- paste
-- Last steps:
set value of cell "A2" of table 4 of theNewSheet to theInvoiceNumberAsText
tell application "System Events" to keystroke "a" using {shift down, command down} -- unselect all
end tell
Secondly, another script which requires cliclick 3.2 to be installed beforehand:
set myInvoices to alias "Macintosh HD:Users:username:Desktop:My invoices.numbers"
tell application "Numbers"
launch
activate
set thisDocument to openmyInvoices
-- Get the number of the next invoice (one sheet per invoice):
set N to (countsheets of thisDocument)
set theInvoiceNumberAsText to "Invoice #" & text 1 through (5 - (countN as text)) of "00000" & N
-- Duplicate sheet 1:
tell thisDocument to set active sheet to sheet 1 -- sheet 1 is used as a template for the other sheets
tell application "System Events" to tell process "Numbers" to ¬
set {x, y} to position of UI element 1 of scroll area 2 of window 1 whose name is "Sheet 1"
do shell script "/usr/local/bin/cliclick kd:ctrl c:" & x & "," & y & " ku:ctrl"
tell application "System Events" to keystroke "Duplicate" & return
set name of sheet 2 of thisDocument to theInvoiceNumberAsText
-- Last steps:
set value of cell "A2" of table 4 of the active sheet of thisDocument to theInvoiceNumberAsText
tell application "System Events" to keystroke "a" using {shift down, command down} -- unselect all
end tell