I'm having an issue with KM after using Automator to copy 2+ filepaths from Finder to the System Clipboard. Unfortunately Keyboard Maestro only receives 1 of the filepaths - the last one.
It starts with an Automator workflow that copies the paths of the current Finder selection and then runs a KM macro:
Unfortunately the above KM action only displays a single filepath. I have a feeling this is a KM issue because when I Paste into a text editor after running the workflow / macro – I get all of the files I selected in Finder as expected.
Something is happening where KM's version of the System Clipboard is only getting the last file selected. For example, if I select files a.png, b.png, and c.png - KM only prints the path of c.png.
Couple questions:
Is this a bug? I can't be sure, but it may have to do with how KM handles newline characters in the System Clipboard.
Is there a better way to pass these arguments to KM, keeping in mind there could be 1 - N of them?
Tested on:
MacOS 12.1, KM 9.2, Automator 2.10
MacOS 10.15.3, KM 9.2, Automator 2.10
The clipboard has a feature where it can contain an array of items. This is basically never used and not generally well supported.
This is distinct from the clipboard item containing an array of flavors (eg rich text, plain text, image, etc).
Keyboard Maestro doesn’t support multiple items in the clipboard.
You can try using the Execute a Shell Script action, with pbpaste and save the result to the clipboard and see if that gets a plain text with the paths.
Hi @kraftyDevil - I’m not sure what it is exactly you’re using your Automator script for, but if it’s just to grab some file paths that you’ve selected in Finder, then KM provides a token %FinderSelections% that contains the paths of the currently-selected items in the Finder; using that would possibly mean you don’t need to resort to Automator and the clipboard.
I'm using Automator so that I can add options to the right-click menu (under Quick Actions).
I select one or more files in Finder, right-click, move my cursor to Quick Actions, and then select from the list. I then have a command line script that accepts the filepaths(s) as input.
It looks like %FinderSelections% is a good idea, but unfortunately it only supports 1 file and I'll need 1+.
Thanks for the idea though. I could use it in the future for scripts that only have 1 file as input
That's incorrect, it returns as many files as are selected. You've probably only read the first part of the wiki entry which talks about %FinderSelection% - notice that's in the singular.