How to test whether Finder selection exists?

I'm having problems to determine whether a file (some files) on the Desktop are selected.

The red part of the macro doesn't work. What's the way to go?

Thanks,
Hans
Create Export folder on Desktop, move selected file(s) to folder.kmmacros (4.6 KB)

You want to establish whether particular files are selected ?

( or just whether the Finder selection is empty – nothing selected at all ?)


If any For Each loop at all is evaluated there, then the Finder selection is non-empty, of course, but have you considered:

token:FinderSelection [Keyboard Maestro Wiki]

Particularly %FinderSelections%

2 Likes

As @ComplexPoint has said, you can use the token %FinderSelections% to test whether anything is selected or not in the Finder.

I noticed a few other things in your uploaded Macro:

  1. You are using Global Variables which means their values are saved after each run, which could cause problems. Much better to use Local Variables (which clear their values each time) for something like this.
  2. No need to find the file name and save to a second Variable - the For Each and the Move a file action can work with a single Variable.
  3. Your test within the For Each was failing to do anything if nothing was selected in Finder (i.e. if nothing was selected the For Each didn't even begin to run) which is why your test to see if a variable was empty wasn't working. The solution is to put the test outside of the For Each loop.

Anyway, I have tried the below and it works for me.

Create Export folder on Desktop, move selected file(s) to folder v3.00.kmmacros (4.5 KB)

2 Likes

Thank you for your thorough explanation and further help.

It seems that the selection is only moved to the Export folder, if no more than one file is selected.

Yes, you are right. That is because I had used the token %FinderSelection% instead of %FinderSelections% ... which means the token was empty if more than one item was selected and also empty if nothing was selected...

I have corrected and replaced the original example Macro I uploaded with a version 3.00

1 Like

Here's the final macro:
Create Export folder on Desktop, move any selected file(s) to folder.kmmacros (5.5 KB)

1 Like