Numbers: menu or list to jump to a specific sheet?
Solution 1:
Is there a way to access a menu or list of all the sheets in a Numbers document, so I can quickly jump to one specific sheet without having to scroll or page one-by-one with the previous/next keyboard shortcuts?
The only way I know of is to AppleScript it and use some mechanism to trigger the script, e.g. an Automator Service1.
As an example, pressing ⌃⌘S in Numbers with a Stocks.numbers document opened and frontmost, I get a choose from list
dialog box as shown in the next image:
I then selected sheet 1-Year History and then clicked OK and was taken to that sheet in the document. Note that double-clicking on any list item takes one to that sheet directly without having to click OK or press Enter. (You can also type the first character of the list item or use down/up arrow keys too.)
Obviously with a Numbers document that has only five sheets this isn't really necessary, and is just an example for when the document has the number of sheets that would necessitate scrolling through the sheets tabs in the document to get to the one wanted. On my MBP 15" Retina display, I was able to see 37 sheets without having to scroll in the Go To Sheet... list box. (This will vary based on the screen resolution and height of the Dock.)
Create an Automator Service1 as show in the next image:
Example AppleScript code:
tell application "Numbers" to set sheetList to name of every sheet of document 1
tell current application to activate
choose from list sheetList with title "Go To Sheet..." with prompt "Please select a sheet name:"
if the result is not false then
my selectSheet(result as text)
end if
on selectSheet(n)
try
tell application "Numbers"
activate
-- # The following code causes Numbers to go to the selected sheet.
-- # It is not modifying the existing data in the target cell, however,
-- # it does cause a saved document to show as edited, temporarily,
-- # and resolved by the code in the following System Events tell block.
set value of first cell of first table of sheet n of front document to ¬
(value of first cell of first table of sheet n of front document)
end tell
tell application "System Events"
-- # Undo Typing so the document doesn't show as edited if already saved,
-- # and if already saved the modified date/time stamp shouldn't change.
keystroke "z" using command down
-- # Press the escape key to remove focus from cell A1.
key code 53
end tell
on error eStr number eNum
display dialog eStr & " number " & eNum buttons {"OK"} ¬
default button 1 with icon caution
return
end try
end selectSheet
AppleScript Code Note: As far as I know, Numbers does not have an explicit AppleScript command to select a given sheet and this is sort of an alternative method and it does cause a saved document to show as edited temporarily, even though it's not altering the value of the target cell, and resolved by the code in the System Events tell block. It works by setting the value of cell "A1"
to it's current value, so while it's perceived as an edit, no data has been altered from its current value and if it was already saved, the modified date/time stamp shouldn't change. This works for me in Numbers 5.1 in macOS High Sierra on a read-write document, and is why I use it. As coded, it is not intended to be used on a locked or read-only document. Additional coding would be necessary for that scenario.
For System Preferences > Keyboard > Shortcuts > Services:
Note: Sometimes with an Automator Service1 and assigning a keyboard shortcut, you may first have to trigger it from the target App's Services menu one time. From then on the keyboard shortcut should work normally.
1 In macOS Mojave an Automator Service is called a Quick Action.
Note: The example AppleScript code is just that and sans the included error handling does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors.