How to Set Variable to Currently Selected Text on Mac?

Hi,

I'm having a brain cramp. Can someone please remind me how to set a keyboard maestro variable to the currently selected text?

Thanks!

Sure, try this:

I always put a short pause after the "Copy" action to make sure the app has time to respond to the copy command.

1 Like

This is always a good idea when working with the clipboard, but keep in mind that the duration of the pause depends upon the app and what is being copied.

0.05 seconds is usually long enough on my system for text-related things.

But with apps like Excel that put their own formats on the clipboard it may take longer.

It's always good to experiment and whittle time off the macro where you can.

-Chris

In theory, if you are using the new Copy action, and 7.0.1, the pause should generally be unnecessary because the Copy action now essentially does this:

  • Simulate Command-C
  • Pause Until the Clipboard Changes
  • Pause for half the normal time it waits after a Command key

So in almost all cases there should be no need for a Pause afterwards. Only applications that put some bits on the clipboard and then take a long while before putting some more bits on the clipboard should cause a problem.

Adobe & Microsoft apps, Java apps, cross platform apps, emulators, and games are the most likely to be a problem.

3 Likes

Thanks! That worked.

Thanks for the reminder, Peter.

I developed the habit of adding a Pause action in KM6 in order to make sure the copy always completed. Seems like I have had to use it in KM7 as well, but I need to revisit/retest some of the macros where I have used it.

  • Pause Until the Clipboard Changes
    That was what I was looking for. Thanks!!

I also use this construction frequently:

image

This topic is about selected text – not selected files and/or folders...

TheFinderFileName may work for you as a variable name, but it's inaccurate.

itemPath is more descriptively accurate.