tell application "Numbers"
tell document 1
tell sheet 1
tell table "2012"
set targetRow to 51
set selection range to range ("A" & targetRow & ":A" & targetRow)
my pasteAtSelection("01/02/2016 azerty 79,99 12345,67 55 01/02/2016 79,99 12345,67 12345,67 01/02/2016")
end tell
end tell
end tell
end tell
on pasteAtSelection(theString)
set the clipboard to theString
tell application "System Events"
tell process "Numbers"
set frontmost to true
keystroke "v" using {command down, option down, shift down}
end tell
end tell
end pasteAtSelection
CAUTION : as I am a french user, the string pasted above use french settings.
For an user from the USA I guess that it would be better with :
“02/01/2016 azerty 79.99 12345.67 55 02/01/2016 79.99 12345.67 12345.67 02/01/2016”
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 25 octobre 2018 17:17:55
If you want to insert the values in a row just above a bottom header row you may use:
tell application "Numbers"
tell document 1
tell sheet 1
tell table "2012"
set bottomRow to (count row) - 1
# I assume that there is a bottom header at bottom of the table
add row below row bottomRow # create a standard new row above the existing header
# Select the first cell of the added row
set selection range to range ("A" & (bottomRow + 1) & ":A" & (bottomRow + 1))
my pasteAtSelection("01/02/2016 azerty 79,99 12345,67 55 02/01/2016 79,99 12345,67 12345,67 02/01/2016")
end tell
end tell
end tell
end tell
on pasteAtSelection(theString)
set the clipboard to theString
tell application "System Events"
tell process "Numbers"
set frontmost to true
keystroke "v" using {command down}
end tell
end tell
end pasteAtSelection
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 25 octobre 2018 19:02:56
I’m a bit surprised because I don’t remember a date when “selection range” wasn’t available.
I can’t check because I don’t have version 3.6.2 for years.
I have version 4.3.1 and version 2.3. Both of them contain “selection range”.
Below is a code which scan the cell 1 of rows starting from the lower standard row.
It was tested with Numbers 5.2
tell application "Numbers"
tell document 1
tell sheet 1
tell table 1
set footers to my getCountOfFooters()
set bottomRow to (count rows) - footers
repeat with r from bottomRow to 1 by -1
# Edit the test if you must check that several cells aren't empty
if value of cell 1 of row r is not missing value then
exit repeat
end if
end repeat
# Here r is the index of the lower cell wich is not empty in column 1 of a standard row.
set targetRow to r + 1
# Select the first cell of the added row
set selection range to range ("A" & targetRow & ":A" & targetRow)
my pasteAtSelection("01/02/2016 azerty 79,99 12345,67 55 02/01/2016 79,99 12345,67 12345,67 02/01/2016")
end tell
end tell
end tell
end tell
on pasteAtSelection(theString)
set the clipboard to theString
tell application "System Events"
tell process "Numbers"
set frontmost to true
keystroke "v" using {command down}
end tell
end tell
end pasteAtSelection
on getCountOfFooters()
tell application "System Events" 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 14 to tell menu 1
repeat with ms from 1 to 6
if value of attribute "AXMenuItemMarkChar" of menu item ms = "✓" then
set footers to ms - 1
exit repeat
end if
end repeat
end tell
end tell
return footers
end getCountOfFooters
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 25 octobre 2018 21:29:38
Numbers 3.6.2 behaves the same way under El Capitan and under High Sierra.
I am accustomed to pass a full range descriptor like “A2:C2” when I call set selection range so when I want to select a single cell I use the same syntax :
set selection range to range “A10:A10”
but we may use a shorter instruction:
set selection range to range “A10”
Both select the cell “A10”
The very first one select the cells “A2”, “B2”, “C2”.
When we want to paste a row, there is no need to select the entire row, select the first cell of the row is sufficient.
Maybe I have find the explanation of what you got.
I defined a name of table which doesn’t exist in the document.
For instance,
tell table “missingTable”
set selection range to range “A10”
display :
tell application “Numbers”
set selection range of table “missingTable” of sheet 1 of document 1 to range “E10” of table “missingTable” of sheet 1 of document 1
→ error number -1728 from table “missingTable” of sheet 1 of document 1
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 26 octobre 2018 16:02:06