“Smart Copy” Macro [SOLVED]

Keyboard Maestro 8.2.4 “Smart Copy” Macro

Hello, I'm just starting to put this macro together but I would like the first 2 actions only to occur if the cursor is not at the start of a unit of text. I've looked at the "If Then Else" action but I cannot work out what condition I should test for.

What I am trying to do is to be able to position the cursor anywhere in a unit of text, and press a key and highlight and copy the entire unit of text to the clipboard. The problem is that if the cursor is at the start of the text, then it jumps back to the previous unit of text.

I hope that makes sense!

If you mean "paragraph" by "unit of text", then this should work:

I was actually talking about a programming code context, so whatever you call the unit of text covered by a [⌥→] keystroke, is what I meant.

Anyhow you've given me some more options to play with, so thanks for that.

How do you get the neat displays of the keystrokes in these forum posts?

It uses these tags:

<kbd>⌘</kbd>

You could easily create a KM macro to do this.

It looks like what I need is to generate a double-click mouse action at the current keyboard-cursor position. I'm looking at the "Move or Click Mouse" action but there doesn't seem to be a way of positioning a mouse click by the current text cursor position unless I'm missing something obvious!

In your terminology, I guess it would be "Double click at current cursor to select word"...

You can use the same pattern I gave you, except substitute word selection for paragraph selection.

  • -- make sure cursor is NOT at start of word
  • ⌥← -- move to start of word
  • ⇧⌥→ -- select entire word

Thanks @JMIchaelTX! That worked a treat. Here's the finished (for now) article...

Smart Copy.kmmacros (3.5 KB)

I had to put some pauses in because otherwise, it messed up the macOS desktop settings. I'm using it in Visual Studio Insiders though I guess it could work in other apps. It's tied to ⌘F13. There's also a Smart Paste tied to ⌘F14 which is the same apart from a ⌘V at the end.

It's designed to replicate the Smart Copy and Smart Paste facility of the legendary CodeRush keyboard enhancement tool for Delphi that I used to use many years ago. The hotkeys are chosen because my muscle memory still remembers the old Windows Ctrl-Insert and Shift-Insert keystrokes, and the ones here are close enough!

Here's the Smart Paste macro as well...
Smart Paste.kmmacros (3.5 KB)

This Keyboard Maestro is pretty cool, isn't it? The next step is to automate some tasks in Logic Pro X!

1 Like

If one of the above posts solves your problem/question as originally stated, please check the "Solved" checkbox (click for details) at the bottom of that post.

Otherwise, please post your remaining questions/issues about this problem.
If you have other questions, please start a new topic.