Select String as a Word in Pages

Double-clicking a word in Pages selects that entire word. However, I want strings such as D#m7/b5 to be treated as word - i.e. it's not a word, but I want the quick action benefit of double clicking it (or similar easy shortcut) and selecting the entire string between spaces.

As far as I can tell, no keyboard shortcut while selecting text does that. How could I set up an automation for that in keyboard maestro?

Hey @Drukinn,

Unfortunately – you can't change the macOS' or any old app's double-click behavior at any level that I know of (other than speed in the system mouse prefs).

Some apps (usually programming editors) may have preferences to allow adjusting for camel-case or variations of it but not many.

What you want to do is not going to be instant, because you'll have to position the cursor at the start or end of the “word” and then:

  • Iterate through it letter by letter with Shift-Arrow to select.
  • Copy
  • Evaluate for whitespace.
  • Repeat until your end condition.
  • Back up if necessary.

Something similar to this:

Pages ⇢ Select "Word".kmmacros (7.4 KB)
Keyboard Maestro Export

If you were working with an app like BBEdit (which is highly AppleScriptable) then a scripted find with regex might do the job, but Pages doesn't have the smarts.


Thanks four your feedback. I've tried this macro, but couldn't get it to work.

I've just submitted a feedback to Apple with a new feature request. One can hope.

Did you make sure the macro and its container macro-group were both enabled after you imported it?

Yes, I did. I think it interferes with another Macro I have.

If your intent is truly to select a chord name, you'll have to use @ccstone's (which does work for me). But if your goal is to copy the chord name to the clipboard, try this:

Get Chord.kmmacros (6.3 KB)

It gets the last non-whitespace run of characters before the cursor, the first non-whitespace run of characters after the cursor, puts them together, and then puts that concatenation onto the clipboard. Its main downsides are:

  1. It gives no visual indication of what's on the clipboard.
  2. The text that's put on the clipboard is plain text—no formatting.
  3. There's some visual "noise" as the portions of the current line before and after the cursor are selected.

Still, it works pretty quickly, and it will copy the chord name whether the cursor is immediately before the name, immediately after the name, or anywhere within the name.

My crazy idea will almost certainly not be something you want to try, but it's so delightfully crazy that I want to mention it. Just for the fun of it.

Step 1. Take a screenshot.
Step 2. Pass the screenshot to Monterey shortcuts' OCR (discussed on another thread)
Step 3. Filter out the text that doesn't contain chord names. (not too hard)

The resulting word that appears is probably the word you want. Because Monterey OCR does not "break up" text.

Somehow I cannot get this to work for me. All is enabled.

What are the error messages?

Also (forgive me if these seem obvious):

  1. Is Pages the active application when you run the macro?
  2. Do you see the portions of the line before and after the cursor get selected and deselected?
  3. Does the clipboard change at all when you run it?

Got it to work now, but it's a bit jittery, i.e. it doesn't execute so fast. I've tested it on Pages.

Should be a selection/deselection to the left and then one to the right. Nothing more. Are you sure you're looking at mine?

If this is a prelude to triggering the Copy Chord Name as Chord Graph macro, it may be worth experimenting with:

  • clicking anywhere in the chord string, so that it contains the cursor,
  • using ⌥ left arrow, then ⌥⇧right arrow

and if that seems to work wherever you are converting chord codes to graphs by applying a font, you could try inserting those two key strokes before the copy event in the main macro itself:


Yes, I was looking for it to work as a prelude to your macro. However, that would still require up to 4 keystrokes to select with a keyboard. That hardly competes with a mouse selection.

As for applying a font style, I do it by line, so no need to select individual chord names in this case. Did I misunderstand you?

I see ... I wonder if I'm missing something ? If those two keystrokes are built into the macro itself, don't you just place a cursor in the code and launch the macro ?

It might work well if built into the macro. I'm just unsure about where to add it into your macro.

Ah ... it's not working in the position shown in the screenshot above (4 posts back) ?

Hey @Drukinn,

I thought of a way to do this provided you can come up with a regular expression that sufficiently covers the possible string permutations.

  • It finds for the next instance of the given pattern
    • Presently in the current line.
    • By changing the Cmd-Shift-Right-Arrow keystroke you can change the scope of the search.
  • The found string is placed in the Find-Pasteboard.
  • Cmd-G is used to select the string.

It's pretty fast on my system.

This is just a proof-of-concept, so don't expect anything fancy.

Select a String with a Particular Format v1.00.kmmacros (8.4 KB)
Keyboard Maestro Export

Not in the macro...

You can avoid using the clipboard by typing a unique character, getting the text with AppleScript, and deleting the anchor character if so desired.

tell application "Pages"
   tell front document
      set documentText to its body text
   end tell
end tell

To bad you can't get the actual selection in the Pages document...


1 Like

I've managed to get it to work on the macro it works beautifully) but it doesn't work when the chord name has characters such as / or #

@ccstone thanks for your input. It works relatively well, with some cases dropping. My biggest issue is that I have to be at the beginning of the string. This is not biggie, however my ultimate automation would be to just place the cursor just anywhere where the string is and the selection would be done for me by the macro then. Much like a double click does with actual words.

You can change that behavior.

Start out with Cmd-Left-Arrow...