Use Folder Action to Copy Latest File to Clipboard

Hi everyone,

Hoping someone smarter than me can assist with a Macro.

Context: I create a lot of presentations for my job and am often downloading numerous image files and then dropping them into Keynote. On most occasions, drag and drop is the easiest way for this to work, however often when taking images from the web I need to download the raw file ahead of bringing it into keynote. This is also the case for screenshots.

I want to have a folder (let's call it 'Temp') that triggers an action whenever a new file is added. The workflow should be quite simple, but I can't get it to work:

  1. File added to 'Temp' folder (triggers KM action)
  2. Keyboard Maestro copies this one file (most recently addded) to my clipboard
  3. I can manually paste into my presentation software

Hope someone can help. Sorry if this is super simple - I'm just getting started.

Hi Simon,
I'm glad I can finally help someone as I asked this exact question sometime ago!

What you need to use for this is the %TriggerValue% variable. See screen shot for an example that should work for what you what.

Screenshot 2020-08-26 at 18.59.23

4 Likes

Thanks so much! I never would have worked this one out...

Hi, I tried this approach to do the same thing on my download folder. However it seems that It only works here when the file is moved there, not when its downloaded. Am I doing anything wrong or is there maybe a good solution to this?

Best Regards
Trond

@peternlewis I can't get this to work on my downloads folder. Any advice to fix? I have it set to this, but it's not copying anything to the clipboard when I download something to my downloads folder.

If the macro is doing nothing, then start by trying the Interactive Help and seeing whether there is a problem or whether the macro is triggering.

If the macro is triggering, then something should be being placed in the clipboard.

Note that the Downloads folder has special protections on it so may need additional permissions, or you may need to give Keyboard Maestro Engine Full Disk Access permission.

1 Like

not sure what exactly did the trick but now its working perfectly. All I did was just quit and restart Keyboard Maestro and now it works :). Seems like sometimes that's all it needs. Thanks for your quick help on this though.

Add a segment of shell code at the beginning, which is used to wait for the browser to finish downloading.

while true; do
  if ! lsof -c "Google Chrome" | grep "~/Downloads" > /dev/null; then
    break
  fi
  sleep 1
done

image

2 Likes

Thanks for that. It seems to be working alright now, but if the problem comes back I’ll definitely be adding that shell script.