Send filename from Afred to a named clipboard

I use this simple workflow to get the filenames of the PDF files. It basically runs a small shell script to copy the filename without the extension:

zBase=$(basename "{query}")
title=${zBase%.*}
echo -n $title;

What I want to do:
Every time I copied the fine name, I want it to go to a specific named clipboard: say Reference. Every time I made a new copy, the new item will replace the old clipboard of the Reference clipboard.

The thing is: I don’t know how to send from Alfred File action into KM. KM doesn’t seem to do any action on Aflred’s search window.

is it possible to do?

You can interact with KM via AppleScript. So you could launch an AppleScript like this with Alfred:

tell application "Keyboard Maestro Engine"
  setvariable "zzzFromAlfred" to "+++Whatever+++"
  do script "D80232B8-CAE1-4FD3-AAF9-8D381D68926A"
end tell

The AppleScript sets a KM variable and then executes this macro which will set the Named Clipboard “Reference” to that variable:

_[test] Set Named Clipboard to Variable.kmmacros (1.4 KB)

1 Like

This worked perfectly.

Thank you very much.

Just so you (and others) know, there is a KM Action to get File Attributes so that you don't have to run a shell script. Many users are not confortable with shell scripts.

See action:Get File Attribute [Keyboard Maestro Wiki]

This KM Action requires the full path to the file which you can get by any of these means:

  • Type in full path
  • Select the file using the "Get File" button in the action
  • Using a KM Variable, like "%Variable%FileFullPath%" which you have set in a previous action, like a Prompt User.