For Each Item - difficulty understanding action

Hey Victor,

Think of a collection as a list.

A list of selected items in the Finder.

A list of lines in a variable.

Etcetera.

The For Each structure is:

For Each <LineVar> in these collections:

Keyboard Maestro enters a variable named Variable as a default, and I always change it to something like LineVar or filePath for clarity.

The Finder Selection Collection works like this:

tell application "Finder"
  set myFinderItems to the selection as alias list
end tell

repeat with theItem in myFinderItems
  # Do something with theItem
end repeat

Except that the list contains Posix Paths rather than aliases.

A super simple example:

Generic-Test 01.kmmacros (3.7 KB)

-Chris

Edited for clarity and to fix markdown-eaten-characters 2016/03/20 10:00 CST

1 Like