Duplicating Text

Hi,

I'm trying to duplicate selected text by pressing Command+D, and I want to keep being able to press Command+D and it will keep pasting that same line over and over again.

Can anyone assist with this workflow?
Thanks!

Since your macro works fine in the app that I tested it on, I guess that means your macro may behave differently for each app you might want to use it on. Therefore, I think you should tell us which app you want this macro to work with.

I am assuming what you mean is:
Press D = copies
Next press of Press D = pastes

So, one hotkey to do two things?

Here is one approach:

If you press D the macro will copy.
If you press D again within 3 seconds it will paste.
If you keep pressing D within 3 seconds of last pasting, it will paste again.
After 3 seconds of inactivity the Macro reverts to original state and D will copy.

This is an Example. You can change the time delay in seconds in the first Magenta Action.

At the moment there are just placeholder Actions for copy and paste to show the Macro operating without it doing anything.

EXAMPLE Copy and Paste with one hotkey.kmmacros (4.8 KB)

1 Like

I noticed that too, but since the result of a paste in any(?) app is the same text that was captured during the previous copy, it may not be a problem that requires any timing code. This may depend upon the app, and he hasn't yet indicated which app he's using. (Even if it's "Alfred" that app has many different windows and he hasn't indicated which window he's using in that app.)

Yes, more information would be helpful to provide a Macro for their actual task. But funnily enough, I wanted to make a "one hotkey two tasks" macro for myself anyway (to use in Apple Mail for Junk filtering) so, this was a good catalyst to getting that done :grinning:

Yes, your solution looks like it could be handy in many situations.

1 Like

I would caution against using a ⌘-D for such a macro, since that hotkey will already be in widespread use. The macro should be in a macro group that is set to be available for only the necessary applications, because you will want the standard ⌘-D behaviour in, for instance, the Finder. But even so, setting such different behaviour for that hotkey in different circumstances might cause some mental friction! In other words, you might keep thinking "If I hit ⌘-D now, am I sure what will happen?".

I reuse ⌘-C and ⌘-V for various macros, but they always mean a variant of "copy"/"paste".

The big problem is that after you've done the first duplication there is no text selected. While apps can behave differently, in most a "Copy" when nothing's selected will result in a beep and (eventually) an action timeout and macro abort.

While you can get round the timeout and abort by changing the "Copy" action's options you'll still get the annoying alert sound -- and, in apps which behave differently to the above, behaviour will be "undetermined".

You can include different branches for different apps -- but probably easier to go with @Zabobon's "timing test" to determine intent.

Spreadsheets, for example, work differently from other apps. You can either select/copy text or cells. There is no "beep" if there is no text selected. We still don't know what the app is that the user wants to use here.