How would I move a number of tagged files one at a time at a particular rate of speed?

Would I use "For Each Item in a collection" and "Finders selection collection"?

I have a group of files. Some are tagged and some are not. I want to process and move the tagged files and leave the rest alone. My plan is to put the tagged files into a folder which responds to them by performing an action on them. If I dump them all into the other folder at once, only one of the files gets processed and nothing happens to the others. If I move them one at a time and pause for, say, a minute, between each move, the process is able to finish and prepare for the next File.

The question is how do I tell the program which items in the folder are in the collection?


Hey @jimmymaciii,

It appears that moving the files with AppleScript into a folder with a Keyboard Maestro Folder Trigger obviates the need for a pause.

This macro takes the Finder selection and weeds-out any untagged files. It then moves them to the destination folder designated by the variable destinationFolder in the script. (See #User Settings in the script.)

Use this macro to create a relative alias of YOUR destination folder to emplace in the script.

Putting Relative-Aliases On The Clipboard

Let me know if you have any problems.


Finder ⇢ Move Selected- Tagged Files to Destination Folder v1.00.kmmacros (6.8 KB)

Thanks! But I have to admit that my programming skills are minimal and I haven't the vaguest idea what the AppleScript you have provided is supposed to do or how it's going to do it.

I know I'm a naive newbie, but it seems to me that if you have a folder with 10 files in it and five are tagged red, that it shouldn't be too difficult to move those files one at a time every 5 minutes to a different folder, but I don't see any way in the "For Each Item in a collection" Action to specify less than all the files in the folder to work on.

Do I understand that correctly or not?

Furthermore, could anybody give me a definition of Finders Selection Collection? Does that mean all the files in a folder that has been selected or does it mean certain files inside a selected folder that have somehow been specified as opposed to files in that folder which have not been specified?

As also opposed a Folder Contents Collection, which I assume would be all the contents of a particular folder.


The answer to your original question may not be obvious, but isn't overly difficult. The way to have a For Each action perform actions only on certain objects (in this case, tagged files) is to have it check every file in the folder (using the Folder Contents collection, as you surmise) but only act on ones that meet certain conditions: again, in this case, if the file being checked is tagged or not. In KM, this can be done by getting each file's tag(s) and setting them to a variable, then checking that variable to see whether or not the file contains any tags. If the file contains no tags, the variable will be empty, and we can leave that file alone; if it is not empty, then we know the file contains at least one tag, and can tell the macro to move the file accordingly. In macro form, it looks like this:

Example Macro.kmmacros (3.1 KB)

The 60 second pause is there to ensure enough time for each file to be processed in the target folder once it has been moved; this can of course be adjusted (or disabled/erased) as necessary.

As to your later question, yes, the Finder's Selection collection works only on files that are currently (manually) selected in the frontmost Finder window, and the Folder Contents collection is indeed every file in the specified folder, without the need for manual selection.

Hey @jimmymaciii,

Which one?

The macro to move the files?

Or the script that creates relative aliases?

If the latter I've turned that into a plain old Keyboard Maestro macro, so It'll be easier to use.

Finder ⇢ Create Relative Alias(s) of Selected Item(s) v1.00.kmmacros

1) Select your destination folder.
2) Run the macro.

The Clipboard will then contain a relative alias to your destination folder that you can paste into the script in the original macro.

In this line of the original macro:

# User Setting:
set destinationFolder to alias ((path to downloads folder as text) & "test_Keyboard Maestro:")

You replace this part:

alias ((path to downloads folder as text) & "test_Keyboard Maestro:")

With what you have just copied to the clipboard.

Then you can run my original macro which will:

1) Take the Finder selection and create a list of aliases (one for each selected item).
2) Remove any NON-tagged items from that list.
3) Move the entire list en-mass to your destination folder.

By doing it this way your Folder-Triggered macro attached to the destination folder should properly see and process each individual item moved – without having to fool around with timing.


This seemed like just what I was looking for, but, when I put it in place and tried it, nothing happened. I ran it through the debugger and couldn't see any problem with it, so I tried to simplify it as seen below.
I ran this through a folder with 7 files, four of them with Red labels. Each text window came back with NO Tag.
Any ideas?

Make sure that the "v" in %Variable%LocalFile% is uppercase, not lowercase; it may seem finicky, but at least as of KM 8.2.1 and earlier, it makes a difference. Change that, and it should work as expected, like this tweaked example macro I verified myself:

Example Macro.kmmacros (4.5 KB)

Thanks! It works just fine now.