How to interact with specific sheets in numbers via AppleScript?
Environment: Mojave (10.14.5), Numbers 6.2 (6369), Automator 2.9 (444.42)
Full Disclosure: Posted same on apple.stackexchange.com, trying to reach wide audience to get answer...
Issue:
Trying to automate process:
- Open specific document
- Switch to specific sheet (sheet 2)
- Manipulate contents of one (eventually many) cell on that sheet
Stuck on #2. Doc opens but never switches to second sheet and through debugging code (via display notification ...'s ) I can tell that it never gets past my various attempts to switch to that sheet (or get it's name, etc.)
The code has been modified many times in attempts to get this to work, but essentially:
on run {input, parameters}
set msg to ""
tell application "Numbers"
activate
try
set msg to msg & " A"
set the chosenDocumentFile to "/path/to/mydocument.numbers"
open the chosenDocumentFile
end try
tell chosenDocumentFile
try
-- *** TBD - BULLET 2 ***
-- (current attempt to get something to work)
set msg to msg & " B1"
repeat with s from 1 to (count of sheets)
tell sheet s
set msg to msg & " B1b"
set n to get name
set msg to msg & " [" & n & "]"
end tell
set msg to msg & " B1c"
end repeat
set msg to msg & " B2"
end try
end tell
set msg to msg & " C"
end tell
set msg to msg & " D"
display notification msg
return input
end run
The displayed message is: A B1 B2 C D
Any help is much appreciated.
FWIW:
I've also looked at a number of threads here:
(removed links to get under the 5000 character limitation on posts - sigh)
- Numbers and Apple Script Help
- Loop through all sheets in Numbers
- Needs an applescript to navigate among sheets
- This is apparently for an older version of MacOS / Numbers and indicates "It uses GUI scripting, which you need to enable in advance", which I don't fully understand and am hoping is not still needed
- AppleScript: Moving between sheets and obtaining name of current sheet
- Similar caveat to above
- Numbers 3.5 Formula "name of sheet"
- Looked somewhat promising, but didn't seem to help/work for me
- ¿How operate with cells of diferents seehts?
MacBook Air 13", macOS 10.14