Collect a list
Builds a list (files, folders, apps, windows, text pieces, numbers and a few other kinds) for a Repeat to go through.
Make a list of kind into into
Keyboard Maestro: For Each collections
Details #
Fills the variable named in into with a list. Pair it with Repeat using forEach and in to do something with each item. The step's output holds count, the number of items.
Choose what to list with kind:
filesandfolders: the contents of the folder in path (~works). Sorted by path. recursive goes into subfolders, hidden includes hidden items, andincludeFoldersadds folders to afileslist.volumes: the paths of mounted volumes, without hidden ones.applications: names of the running apps that show in the Dock.windows: names of the front app's windows.finderSelection: paths of the items selected in Finder, one item each.variables: the names of the variables set in this run. Names starting with__and theerrorvariables are left out.dictionaries: the names of the variables that hold records.dictionaryKeys: the keys of a record, sorted. Given a list instead, it gives positions 1, 2, 3.json: the items of a JSON list, or the keys of a JSON object.substrings: the pieces of text that match regex. With no regex, one item per character.range: numbers from from to to counting by step (default 1, may be negative).pastClipboards: the text of recent clipboard history entries, newest first, up to limit (default 20).foundImages: always an empty list today.lines: the lines of text.
For dictionaryKeys and json, the source is name (a variable) or else value. Text is parsed as JSON. path then walks into it, as in items[0].name.
Parameters #
| Parameter | Type | Required | Values | What it does |
|---|---|---|---|---|
into | text | Yes | The variable that receives the list. Required. | |
kind | one of | Yes | files folders applications windows volumes finderSelection variables dictionaries dictionaryKeys json substrings range pastClipboards foundImages lines | One of the kinds above. Required. |
from | any value | , to, step: The numbers for range. from and to are required; step cannot be 0. | ||
hidden | yes / no | Include hidden items. Default off. | ||
includeFolders | yes / no | With files, list folders too. Default off. | ||
limit | number | How many entries pastClipboards returns. Default 20. | ||
name | text | The variable to read, for dictionaryKeys and json. | ||
path | text | The folder, for files and folders. Required there. Also the walk path for dictionaryKeys and json. | ||
recursive | yes / no | Go into subfolders. Default off. | ||
regex | text | The pattern for substrings. | ||
step | any value | |||
text | text | The text for substrings and lines. | ||
to | any value | |||
value | any value | A literal source for dictionaryKeys and json, used when name is empty. |
Every step also accepts label, onFailure, timeout and dryRunSafe.
Examples #
- List lines into colors
- Repeat for each color in {{colors}}
- Show “{{ i }}: {{ color }}” for 1 s
- List range into evens
- Show “{{ length(evens) }} numbers” for 2 s
Gotchas #
filesandfoldersfail with "no folder at ..." when the path is not a folder, and with "collect files needs a path" when you give none.applications,windowsandfinderSelectionuse AppleScript through System Events or Finder, so they need Automation permission for those.rangefails if it would be longer than 10,000 items. A badregexfails with "isn't a valid regular expression".pastClipboardsneeds the Switchboard Engine and its clipboard history; without it the step fails.A kind that is not on the list fails and names all the valid ones.
In a dry run the step is simulated unless it is marked
dryRunSafe.