For Each action creates temporary list of items? [SOLVED]

I have this macro to normalize audio files in Finder by normalizing each file using the For Each action (Finder Selection). When I have long files that take longer to convert, I wonder if selecting another file that's not an audio file causes an error?
Example:

I select fileA.mp3 and fileB.mp3 and run the macro. While it's processing fileA, if I then select for example a folder or a text file (anything that's not fileB), will it try to convert any of those files (folder, text file, etc), because the action is set to For Each Finder Selection, or KM automatically makes a list of all paths when the For Each starts running? So when it starts the For Each action, does it know that the files to convert are fileA and fileB, even if I then unselect them and/or select other files while it's still processing fileA?

Or should I always create a For Each action before that one and save that list of items as a variable and then use the second For Each (the one that actually normalizes the audio) to target the lines on that variable?

The list of files that the For Each Action will process is the list of selected items at the time the For Each Action starts to process. Once the For Each processing has started, selecting different files in the Finder will not alter that initial list.

You can test this by making a simple Macro that just displays the path of each file followed by a long pause of say, 5 seconds. You will see that once the For Each has begun, altering the Finder selection makes no difference to the list of files displayed.

The only thing to bear in mind is that the "list" is formed when the For Each Action begins (i.e. not when the Macro begins). So if you had a very complex Macro that took some time to do other Actions before reaching the For Each Action and you altered your selection during that time then the list would be different. Again, a test Macro that has a long pause at the start can show this working.

1 Like

Yes, I tested that and it in fact shows the files that were selected, even if I select another one.

Sure, I totally see that this would be the case. For this particular scenario, the For Each action is the first one, so no issues there. For other macros, it would be safer to save the list as a variable as the first action.

Thank you for the tips.