File attribute
Passes when a file or folder attribute, such as its size, modification date, tags or extension, compares the way you ask.
attribute of path op value
Keyboard Maestro: File Attribute (Is, Contains, Is Before, Is After)
Details #
Reads one attribute of the file or folder at path and compares it with value using op. ~ in the path is expanded.
The attribute names are Keyboard Maestro's: FileType (File, Folder or Symlink), Size (bytes), CreationDate, ModificationDate, AddedDate, LastUsedDate, DownloadedDate, WhereFrom, OwnerName, OwnerID, GroupName, GroupID, POSIXPermissions (octal text such as 644), ExtensionHidden, Invisible, HFSCreatorCode, HFSTypeCode, ContentType (a type identifier), ContentKind (such as "PDF Document"), Tags (a list), Comment (the Finder comment), ParentPath, Name, BaseName, Extension and DisplayName. Four more serve Hazel's conditions: ColorLabel (none, gray, green, purple, blue, yellow, red or orange), Contents (the text of the file, from Spotlight or, for a file up to 2 MB, read directly), Depth (how many folders deep the file is under the folder named in root; 0 is directly inside it) and LastMatched (when Remember a file as handled last recorded the file under the key in state).
The operators: eq, ne, lt, gt, contains, startsWith, endsWith, matches (a regular expression), conformsTo (a ContentType that is, or is a kind of, the type you name: public.image holds for a PNG), and for dates before, after, inLast and notInLast (a length of time: 3 days, 2 weeks, 18 hours). Text comparisons with eq, ne, contains, startsWith and endsWith ignore case. For a date attribute, value can be seconds since 1970, an ISO 8601 date, 2026-10-24, 2026-10-24 09:30[:ss], or a phrase the system can read as a date; for dates, eq and ne allow one second of difference. With a list such as Tags, contains tests for one item.
The trace shows the path, the attribute and the actual value read. Reading a file is harmless, so it happens for real in a dry run too.
Every condition accepts "negate": true, which flips the verdict. The trace records what was compared before the flip, so a negated condition that blocks a macro still shows the real values.
Conditions in an Only if list combine with all: every one must pass, and an empty list always passes. An if step or a repeat loop takes a match of all (default) or any.
Parameters #
| Parameter | Type | Required | Values | What it does |
|---|---|---|---|---|
attribute | text | Yes | One of the names listed above. Defaults to Name. | |
op | one of | Yes | eq ne lt gt before after contains matches gte lte startsWith endsWith inLast notInLast conformsTo | One of eq, ne, lt, gt, before, after, inLast, notInLast, contains, startsWith, endsWith, matches, conformsTo. |
path | text | Yes | The file or folder. ~ and {{ }} work. | |
root | text | For Depth: the folder the depth is counted from. | ||
state | text | For LastMatched: the key file.remember used. | ||
value | any value | What to compare with. Defaults to empty text. |
Examples #
- If the file type of “Applications” is “Folder”
- Show “Applications is a folder”
- Else
- Show “Applications is not a folder”
- If the size of “true” is above 1000000
- Show “Larger than 1 MB”
- Else
- Show “1 MB or smaller”
Gotchas #
A missing file, or an attribute the file doesn't have (
WhereFromon a file you made), makes the condition fail rather than error, and the trace showsfound: false. Negating it therefore passes. Test File exists first when that matters.An unknown attribute fails with
unknown file attribute "...". Names are case sensitive.A date can only be compared with
eq,ne,lt,gt,before,after,inLastandnotInLast; anything else fails witha date can't be compared with "...".Sizeis in bytes andltandgtcompare numbers, so1000000is one megabyte.