That was a nice try, the way you wrote that macro.
But the answer depends upon what you mean: (a) do you mean is there some way to control those features in Numbers without using the mouse and keyboard, or (b) do you mean is there some way to control those features by virtue of using the KM actions which control the mouse and simulate keystrokes?
I can answer (b), yes you can control those features using the FindImage action and sending mouse clicks to the window. But anytime a macro uses FindImage, then we can't upload solutions for you because all solutions depend on things like screen DPI and light/dark mode settings. Are you trying to manipulate a few font features, or all of them? It would be a lot of work creating macros and code that can control every single feature in Numbers. If there's one feature that's really vital for you, tell me which one it is and I'll write some code for you, which you can use as an example for the rest of Numbers.
As for (a), I did open the Script Editor, and opened the Numbers Library, and saw some support for fonts, colours, etc. But we'll need an AppleScript expert to advise us here.
On initial review, the task seems somewhere between difficult and impossible. There's no AppleScript support for styles, and only formatting at the basic level (font, size, bold, italic, etc.). Using Keyboard Maestro's Press a Button action, it returns a long list of buttons in Numbers, but none are actually clickable with the action.
But there's one saving grace to the Numbers sidebar: It's always fixed relative to the top right of the Numbers window, varying only based on what you have showing in the header. For my Numbers, which looks like this...
...the gear icon is -50 pixels in from the right edge and 332 pixels down from the top edge. Using that knowledge, you can write some macros which run very well in Numbers. Because the pixel locations don't change as you resize the window, they should keep working. Note that they will probably break if you change your screen resolution, so they're not ideal ... but so much simpler than doing this stuff by hand.
Here's a demo macro that works on my setup (as shown above) to apply a yellow highlight to a cell.
Macros are always disabled when imported into the Keyboard Maestro Editor.
The user must ensure the macro is enabled.
The user must also ensure the macro's parent macro-group is enabled.
System information
macOS 14.5
Keyboard Maestro v11.0.3
It runs very quickly, and puts the mouse back where it was when you invoked the macro. You may have to change some of the values based on your display and Numbers layout, but hopefully this gets you started.
If you can keep the menu onscreen when Numbers isn't in the foreground (or if you can get back to the menu you need to see in Numbers within a few seconds of clicking Get), just click the Get button in the Click Mouse action, then put your mouse where you want it to click.
If that can't work (often it can't), then I just use Shift-Cmd-Ctrl-4, with my mouse at the "start" location. Drag to the desired target, and you'll see the pixels in the display:
My target is 103 pixels to the right and 96 pixels down from where I started dragging.
If you look at my macro, you'll see the first click is based on the top right corner, but then others are based on the current mouse location, as that seems simpler to me than always measuring from the top right. But either method should work; just make sure you change the setting in the action to match where you measured from.
Edit: And oops, that last action (which restores the mouse location) should be just a move, not a move and click.
Edit: This will also only work when the Text tab is active. You could automate clicking that, too, though if you wanted to—it's also fixed from top right.
great. thanks very much ! It would be nice to have a way to be able to get the screen coordinates with respect to the front window instead of the screen.
I suspect someone could make a macro to help with that.
After using it a long time I can get it to work 99% of the time, and I'm also good at handling errors so that it tries repeatedly until it gets it.
You should try Digital Color Meter in the Utilities folder in Applications. It's handy because it also shows you a zoomed in area around your mouse pointer. (You may have to turn on the flag View / Show Mouse Location the first time you use it.) It's also handy because it shows the RGB values of the pixel under the mouse.
Clicking the text tab is simply with a press button action.
Since you have a talent for thinking out of the box, can you think of a way to create a macro to get the mouse cursor coordinates using the top right corner of the front window as a reference ? I created many formatting macros using your method yesterday. The only inconvenient is that both using "get" and using changes in coordinates using your method are a bit time consuming, which would be resolved by a tool to get the mouse cursor coordinates using the top right corner of the front window as a reference.
I tried creating a script with chatGPT but it did not work. Script and Error message below.
thanks very much !
-- Get the front window's position and size
tell application "System Events"
tell (first application process whose frontmost is true)
set windowInfo to get properties of front window 1
end tell
end tell
-- Extract the necessary information
set windowX to value of attribute "position" of windowInfo as list
set windowY to item 2 of windowX
set windowX to item 1 of windowX
set windowSize to value of attribute "size" of windowInfo as list
set windowWidth to item 1 of windowSize
set windowHeight to item 2 of windowSize
-- Get the mouse coordinates
set mouseCoordinates to do shell script "eval $(/usr/bin/env python -c 'import sys,Quartz;d=Quartz.NSEvent.mouseLocation();print \"x=\" + str(int(d.x)) + \"\\ny=\" + str(int(Quartz.CGDisplayPixelsHigh(0)-d.y))'); echo $x $y"
set mouseX to word 1 of mouseCoordinates as integer
set mouseY to word 2 of mouseCoordinates as integer
-- Calculate the mouse coordinates with respect to the top right corner of the front window
set mouseXRelative to mouseX - (windowX + windowWidth)
set mouseYRelative to mouseY - windowY
-- Output the relative coordinates
display dialog "Mouse coordinates relative to the top right corner of the front window: (" & mouseXRelative & ", " & mouseYRelative & ")"
KBM error message
2024-06-26 07:22:10 Execute macro “zz test mouse coordinates” from trigger Editor
2024-06-26 07:22:11 Action 16011836 failed: Execute an AppleScript failed with script error: text-script:195:196: script error: Expected end of line but found number. (-2741)
2024-06-26 07:22:11 Execute an AppleScript failed with script error: text-script:195:196: script error: Expected end of line but found number. (-2741). Macro “zz test mouse coordinates” cancelled (while executing Execute AppleScript).
As long as what you want are distances from corners of windows, it's built in to the "get" feature of Move Mouse. Here's my mouse at (roughly) the same location within the frontmost window:
If you do @griffman's ⇧⌃⌘4, the initial numbers are displayed as absolute coordinates. But as soon as you click and start to drag they become relative to the click-point.
So click at the top-left corner of the front window, drag to where you want, and the numbers displayed will be the coordinates relative to the top-left corner of the front window.