Select a Newly Duplicated (Copied) File

Hello Everyone.

I have a question that is probably very easy for anyone Keyboard Maestro savvy which I'm definitely not.

I have created a macro to duplicate a file and increment its name (or append " 2" after the base name if it doesn't finish with a number itself). But I would like that new created file to be the selected one once the macro is finished, not the source one. How would I do that please?

Thanks a lot for your help.

Duplicate and Increment.kmmacros (6.9 KB)

Hey Brett,

Welcome to the forum!   :smile:

You can add an Execute an AppleScript action with the following code:

tell application "Keyboard Maestro Engine"
   set itemName to getvariable "newFileName"
end tell

tell application "Finder"
   tell front window
      select item itemName
   end tell
end tell

-Chris

Wow thanks a lot I really appreciate your help.
At first I thought the AppleScript didn't work but that was because I was testing with a file on my Desktop, so I suppose the "tell front window" was the issue. When trying in a floating window finder it works flawlessly.

Hey Brett,

Stupidly macOS doesn’t' allow you to select items on the Desktop via AppleScript...

I've changed the script, so if the insertion location is the Desktop a window will open and the item will be selected.

-Chris

tell application "Keyboard Maestro Engine"
   set itemName to getvariable "newFileName"
end tell

tell application "Finder"
   tell (get insertion location)
      select item itemName
   end tell
end tell
1 Like

Awesome, works very well thank you again. Fascinating the amount of time one can spend to spare a few future seconds now and then, lol.

:sunglasses:

You'd be surprised at how much time those few seconds add up to over days, and months, and years.

Not to mention the reduction of tedium, aggravation, and other stress.

Many of my macros turn a multi-minute job into a fraction of a second.

-Chris

Yeah totally. Not to mention it's satisfying and gratifying when the computer is doing what we expect from them: do stuff for us :wink:

1 Like