Select String as a Word in Pages

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:

keys

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...

-Chris

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...

OK, @ccstone's use of the Find Pasteboard inspired me to give this one last try:

Get Chord.kmmacros (7.5 KB)

This macro will select the whitespace-delimited string that the cursor is in or adjacent to. It does not put that string on the clipboard, although that could be done by adding a Copy command to the end. It's very fast on my M1 MacBook Air, although there is a bit of visual noise as it selects pieces of the current line to set up the search string.

It works if a portion of the whitespace-delimited string is selected, like if you double-clicked on a chord name and got just part of it. It does not work if the cursor is at the beginning or end of a line, although I suspect a little bit of defensive coding could fix that.

3 Likes

It works! Pretty cool, thanks