I want to be able to alternate the active sheet in numbers file.
I can do this with some GUI scripting at the moment, but I want to be able to do this via sheet names. Doesn’t seem to be work at the moment.
Is this possible, to activate a sheet within document by their name
Thanks
As far as I know, feature unavailable in Numbers '09.
Thanks to Nigel Garvey, I’m using this handler (with an auxiliary one)
--=====
(*
==== Uses GUIscripting ====
*)
on selectSheet(theDoc, theSheet)
(*
most of this handler is from Nigel Garvey
*)
local maybe, targetSheetRow
try
tell application "Numbers"
activate
set theDoc to name of document theDoc
(* useful if the passed value is a number. Checks also that we passed the name of an open doc *)
end tell -- Numbers
on error
if my parleAnglais() then
error "The spreadsheet "" & theDoc & "" is not open !"
else
error "Le tableur « " & theDoc & " » n'est pas ouvert ! "
end if -- my parleAnglais
end try
try
tell application "Numbers" to tell document theDoc
set theSheet to name of sheet theSheet
(* useful if the passed value is a number. If we passed a string, checks that the sheet "theSheet" exists *)
end tell -- Numbers
on error
if my parleAnglais() then
error "The sheet "" & theSheet & "" is unavailable in the spreadsheet "" & theDoc & "" !"
else
error "La feuille « " & theSheet & " » n'existe pas dans le tableur « " & theDoc & " » ! "
end if -- my parleAnglais
end try
set maybe to 5 > (system attribute "sys2")
tell application "System Events" to tell application process "Numbers"
tell outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window theDoc
if maybe then (* macOS X 10.4.x
'(value of attributes contains 0)': '(value of attribute "AXDisclosureLevel" is 0)' sometimes works in Tiger, sometimes not.
The only possible instances of 0 amongst the attributes are the disclosure level of a sheet row and the index of the first row, which represents a sheet anyway.
Another possibility is '(value of attribute -1 is 0)', which makes me uneasy. *)
set targetSheetRow to first row where ((value of attributes contains 0) and (value of first static text is theSheet))
else (* macOS X 10.5.x or higher *)
set targetSheetRow to first row where ((value of attribute "AXDisclosureLevel" is 0) and ((groups is {}) and (value of first static text is theSheet)) or (value of first group's first static text is theSheet))
end if -- maybe.
tell targetSheetRow to set {value of attribute "AXSelected", value of attribute "AXDisclosing"} to {true, true}
-- Focus the "Sheets" column ('outline 1 .') AFTER the target row is selected.
set value of attribute "AXFocused" to true
delay 0.1
set maybe to (get value of attribute "AXPosition" of targetSheetRow)
end tell -- outline.
end tell -- System Events
end selectSheet
--=====
on parleAnglais()
local z
try
tell application "Numbers" to set z to localized string "Cancel"
on error
set z to "Cancel"
end try
return (z is not "Annuler")
end parleAnglais
--=====
Yvan KOENIG (VALLAURIS, France) mardi 22 juin 2010 18:02:39