Selecting a File or Files Pasted in Finder

Hi all,

I have Googled and read the Wiki but I still can’t work out how to select the last used file in Finder. Let me explain...

Let’s say I copy a file, open a new folder and paste the file. What I would like is for that pasted file to be selected so that I can do something else to it like rename it. However, once the paste is complete no file is selected.

Any ideas?

Thanks

most recent modificationDate in the contents of the folder ?

the full path of the file ? (path of folder combined with filename of copied file) ?

The file name you can get from the text component of the clipboard.

The part which I only know how to do in script is updating the active selection in a Finder window.

(Perhaps others know some other route ?)

Here, FWIW (using a KM Execute a JS for Automation action) is a sketch:

Paste the copied file, and select in Finder.kmmacros (19.7 KB)

but ... it is suggested here

[macos - Finder: Select a file after Copy & Paste](https://apple.stackexchange.com/questions/240144/finder-select-a-file-after-copy-paste)

that all we need to do is to clear the existing selection in the Finder

(pasting into a Finder window won't displace any existing selection, but apparent it will create one where no selection exists)

I haven't tried the experiment, but perhaps it might:

  • be an alternative to a macro
  • or at least suggest a simpler encoding of the macro (clear selection then paste)

Thank you. It seems this may be more complicated than I was expecting.

The article tells us that some combination like ⌘⌥A clears the Finder selection.

Have you tried automating the sequence of:

  • Keystroke to clear selection in active Finder window
  • (possibly a fractional delay ?)
  • Paste from clipboard

?

This does not work in macOS 10.12.6 Sierra, so I'll be surprised if it works in later versions of macOS.

If you have access to one or more later versions please test and report back.

-Chris

OK, the first thing to observe is that the last file put into a folder may NOT be the file with the most recent modification date. The properly you want to use is Date Added.

So, here's a simple example macro that will return the full path to the file last added to a given folder.

  • No need for a script
  • No need to select in Finder -- path returned in KM

Example Output

Files Sorted by Date Added

image

Macro Results

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MACRO:   Get Path to File Last Added to a Folder [Example]

-~~~ VER: 1.0    2021-01-24 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Get Path to File Last Added to a Folder [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


ReleaseNotes

Author.@JMichaelTX

PURPOSE:

  • Get Path to File Last Added to a Folder [Example]

NOTICE: This macro/script is just an Example

  • It is provided only for educational purposes, and may not be suitable for any specific purpose.
  • It has had very limited testing.
  • You need to test further before using in a production environment.
  • It does not have extensive error checking/handling.
  • It may not be complete. It is provided as an example to show you one approach to solving a problem.

REQUIRES:

  1. KM 8.0.2+
  • But it can be written in KM 7.3.1+
  • It is KM8 specific just because some of the Actions have changed to make things simpler, but equivalent Actions are available in KM 7.3.1.
    .
  1. macOS 10.11.6 (El Capitan)
  • KM 8 Requires Yosemite or later, so this macro will probably run on Yosemite, but I make no guarantees. :wink:

MACRO SETUP

  • Carefully review the Release Notes and the Macro Actions
    • Make sure you understand what the Macro will do.
    • You are responsible for running the Macro, not me. :wink:
      .
  • Assign a Trigger to this maro.
  • Move this macro to a Macro Group that is only Active when you need this Macro.
  • ENABLE this Macro.
    .
  • REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:
    • ALL Actions that are shown in the magenta color

USE AT YOUR OWN RISK

  • While I have given this limited testing, and to the best of my knowledge it will do no harm, I cannot guarantee it.
  • If you have any doubts or questions:
    • Ask first
    • Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.

1 Like

Hey Craig,

Life is often like that...  :sunglasses:

This works with all test cases I've thrown at it so far on macOS 10.12.6 with Keyboard Maestro 9.2 – even a 250MB movie file.

Note that I'm using V which is copy rather than V which is move.

-Chris


Finder ⇢ Paste a File or Folder and Select It v1.00 @ccstone.kmmacros (9.9 KB)

Thanks everyone for your input. Some of it is a bit complex for me, but I tried to follow the Macro you posted @JMichaelTX re sorting through a list of files to get the one that was created most recently. This seemed to work sporadically. Not sure if it wasn't refreshing which file was newest or something.

Anyway, there is usually more than one way to solve an issue and I think I found it. So one of the things I wanted to do was to make an Alias of a file that I had moved. However, Alias is only available n KM by selecting the menu item or hotkey, so the file had to be selected. I then discovered that in Automator I can also create aliases. So I set up a simple Automator folder workflow which creates an alias for any file added to a certain folder. This now works in parrallel with the KM Macro that moves the file to that folder in the first place :slight_smile:

Two things:

  1. My macro finds the file "Last Added" to the folder, NOT the most recently created file.
  2. You many need to add a short Pause (0.2 - 0.5 sec) AFTER you paste the file to the folder.