First the easy one:
Michelle Steiner wrote: What I can't figure out, though is why this doesn't work:
tell application "Numbers" set thisSheet to sheet 1 of document 1 set SheetName to name of thisSheet set thisTable to table 1 of sheet SheetName end tell
It's a scoping issue. You need:
tell application "Numbers" set thisSheet to sheet 1 of document 1 set SheetName to name of thisSheet set thisTable to table 1 of sheet SheetName of document 1 end tell
However, Yvan's question still stands, as there is no selection property for the document. If you only have a single sheet and table, then yes, it's trivial. Multiple sheets, and even better, multiple tables per sheet, complicate things. Take a look at the Net Worth template.
I haven't been able to determine a "proper" way to do this, though I'm happy to be corrected. I went on a wild goose chase with GUI scripting, but it was extremely slow. This isn't pretty, but it's less complicated, and faster than GUI scripting.
tell application "Numbers" tell document 1 repeat with s in every sheet tell s repeat with t in every table tell t if selection range exists then return selection range -- or do something useful end if end tell end repeat end tell end repeat end tell end tell |