Can Keyboard Maestro help overcome the very tedious task of formatting text in the Numbers app

Formatting text within cells in Numbers is very (extremely) tedious. Formatting is buried deep within sub sub menus.

As an example, see the multiple levels of menus under which "highlight" is buried. Same applies to color text etc

The KM apply style to clipboard action does not work.

Press button and click at found image actions have very limited utility.

thanks in advance for your time and help !

highlighting text

Screenshot (click to expand/collapse)

apply clipboard style KM action does not work

Screenshot (click to expand/collapse)

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.

1 Like

thank you for your reply.

In this instance, I found click at found image not reliable and frustrating despite playing with all parameters

I am looking for a way to use KM actions to access those sub-menus.

"Numbers Library" ? where ? I have the script editor and can't see any libraries ?

thank you

Shift-Command-O in Script Editor to open a library.


1 Like

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.

Download Macro(s): Set yellow background.kmmacros (6.6 KB)

Macro screenshot

Macro notes
  • 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.


1 Like

brilliant ! excellent idea ! thank you very much !

one question:

What kind of digital instrument should I use to measure distances in pixels as in

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.


1 Like

OK. thanks very much !

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.


1 Like

sorry to bother you again

would you happen to know where this Keyboard Shortcuts is defined in settings ? or what it's called ?

It's capture region to clipboard, but you can use Shift-Command-4 just as easily (capture to file), as you'll cancel out before saving.

System Settings > Keyboard Shortcuts > Screenshots:


1 Like

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.

1 Like

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:

Notice the greatly different X values, as the first one is based on the top right corner, and the second the top left corner.

Do you need something different than that?


1 Like

no, I understand now. thanks very much !

You could create a 'paragraph' style for the highlight that you want and assign a keyboard shortcut to that style.

EDIT: This will overwrite your font style. But you could create MULTIPLE styles for different fonts you're using.

Now F1 Gives me a yellow highlight


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.

1 Like

excellent idea which I will implement. thank you very much !

brilliant !!! very useful for this case and many others. You solve one of my recurring irritants ! thank you very much