I sent this complementary report:
I was fooled by the oddity in the make new table function.
Look at this script:
tell application "Numbers"
activate
tell document 1
set nn to (get name of sheets)
set nameOfSheet1 to get name of sheet 1
tell sheet 1 to make new table
end tell
end tell
Run it with a document containing two sheets.
If you select sheet 1, the table is created in this sheet and the name of sheet 1 is "Feuille 1" as displayed in the log below:
tell application "Numbers"
activate
get name of every sheet of document 1
{"Feuille 1", "Feuille 2"}
get name of sheet 1 of document 1
"Feuille 1"
make new table
table "Tableau 5" of sheet "Feuille 1" of document "Sans titre"
end tell
but
if you select sheet 2 before running the script, the table is created in sheet 2 but name of sheet 1 is always "Feuille 1" as displayed in the log below:
tell application "Numbers"
activate
get name of every sheet of document 1
{"Feuille 1", "Feuille 2"}
get name of sheet 1 of document 1
"Feuille 1"
make new table
table "Tableau 5" of sheet "Feuille 2" of document "Sans titre"
end tell
a reference to sheet 1 has different meanings given the running instruction
It's perfectly odd.
The only interesting feature of this oddity is that it gave me a way to grab the name of the current sheet:
--[SCRIPT]
display dialog my grabCurrentSheetName()
on grabCurrentSheetName()
tell application "Numbers"
tell document 1 to tell sheet 1
set tName to "temporary_yraropmet"
set newTable to make new table with properties {name:tName}
try
newTable as text
on error errMsg number errNum
set sheetName to item 4 of my decoupe(errMsg, quote)
end try
delete newTable
end tell
end tell
return sheetName
end grabCurrentSheetName
--=====
on decoupe(t, d)
local l
set AppleScript's text item delimiters to d
set l to text items of t
set AppleScript's text item delimiters to ""
return l
end decoupe
--=====
--[/SCRIPT]
Yvan KOENIG (from FRANCE jeudi 15 janvier 2009 14:45:05)