Leave changed text selected

When I use a macro to paste text, is there a way to leave that pasted text selected?

1 Like

That may depend on where you are pasting it – selection and cursor movement mechanisms can vary a bit between text editing applications.

1 Like

Here's a crude first draft that seems to work in most apps:

Paste text and select pasted text.kmmacros (3.4 KB)

Macro image

Keyboard Maestro Export

Note: it's a bit faster to filter with Word Count instead of Character Count then use ⌥⇧Left Arrow, because each arrow in the Repeat block takes a bit of time. Unfortunately, that method doesn't work when the text contains newlines. I'm sure this could be improved with some better logic and/or getting some scripts involved.

Frequently the sequence:

  • Paste
  • Command-Z Undo
  • Command-Shift-Z Redo

will leave the text selected.

But it depends on the editor.

1 Like

Thanks. I am using Mellel and your suggestion doesn’t work with Mellel. Thanks for your help. Any other ideas? It would be a nice option on the Paste command to leave the text selected.

The only other option I can think of would be to simulate N Shift-Left Arrows where N is the length of the text in characters. Even this will not necessarily work in all cases.

Which part doesn't work?
Does switching "Insert text by pasting" to "Insert text by typing" change anything?

The macro I posted uses Shift-Left Arrows as Peter suggested. Are you able to Shift-Left Arrow manually in Mellel to select the text?

1 Like

One other idea: does Mellel support bookmarks? If so, one could insert a bookmark first and insert the text in this bookmark. Then select the newest bookmark.

@billmounce Did you enable the macro group "Testing"?

You are pasting RTL text, or both LTR and RTL ?

( The behaviour of the cursor key combinations in Mellel seems to depend on a quadrant of conditions – the cartesian product of the GUI's Direction state * whether the pasted material is in an RTL script or an LTR script )

But ⌥⇧← does seem to work consistently here in Mellel 6, with RTL and LTR, when the editor direction setting corresponds to the type of writing system.

The local_ContentLen on the %SystemClipboard% and some simple built-in Mac keypresses works for this as well.

Here's the basic premise: Copy the text to the clipboard, get the line length count (`local_ContentLen'), (I added some returns here first to paste the text, but this for testing purposes) Paste the text, then use the Repeat of the line length with Opt+UpArrow to take the cursor to the beginning of the pasted text. After this use the line length count to do a Shift+Down Arrow that will select the lines of the pasted text.

Perhaps a bit inelegant but it is fast. Works with either a single word or multiple lines.

Select Pasted Text.kmmacros (6.1 KB)

1 Like

Looks promising.

  • Not quite sure that I understand the role of the Copy action at the top
  • In Mellel RTL at least, this does select the pasted material, but doesn't, of course. paste it in the selected line. (If we leave in place those returns in the "Optional placement of Pasting" group).

(if we remove that "placement" group, the selection overshoots the pasted material, including the whole of the current line – including existing, unpasted material – and also selected a few existing lines above the pasted text too)

It's superfluous. When I made the original macro, I simply wanted to add some "do something" flavor to it so that the requested functionality could be seen in the context of a larger macro.

(In this case, the made up context was "with text selected, the macro transforms the text, overwrites with a paste, then selects the pasted text")

The Copy was for testing purposes. It is "superfluous" as @avtraino said.

I must say, this request took me down a rabbit hole that I wasn't expecting. It seemed at first like something so simple, yet the more I researched it, the more challenging it became. In any regard, I learned a lot in the process.

My previous KM macro doesn't work in programs like InDesign and for that I had to resort to using Javascript. I assigned a keyboard shortcut to the script there. If anyone is interested in the script, let me know.

However, working with Text Edit, Mail, and Word this (attached) improved version does work! I used the cntrl+shift+v as the trigger as it was very close to the Paste command and Paste Special, yet unassigned for these programs.

Let me know if there are any issues with this or your thoughts on it.

Select Pasted Text (Word).kmmacros (4.1 KB)