Get or set a file attribute
Reads or changes a file's size, dates, tags, Finder comment, permissions and other attributes.
op attribute of path
Keyboard Maestro: GetFileAttribute, SetFileAttribute
Details #
Reads or changes one attribute of one file or folder. op is get by default. Attribute names are matched ignoring case and spaces, so modificationDate, Modification Date and modificationdate are the same.
Attributes you can get:
Name parts:
name,baseName,extension,displayName,parentPath.Content:
size(bytes, as a number),fileType(File,Folder,Symbolic LinkorAlias),contentType(a type identifier such aspublic.plain-text),contentKind(the Finder's description).Dates, as
yyyy-MM-dd HH:mm:sstext in local time:creationDate,modificationDate,addedDate,lastUsedDate,downloadedDate. An unknown date is empty.Origin and owner:
whereFrom(one address per line),ownerName,ownerID,groupName,groupID.Flags:
posixPermissions(octal text, like644),extensionHiddenandinvisible(true or false).Finder data:
hfsTypeCode,hfsCreatorCode(four characters, or empty),tags(one per line),comment.
Attributes you can set: creationDate, modificationDate, groupName, groupID, posixPermissions, extensionHidden, invisible, hfsTypeCode, hfsCreatorCode, tags and comment. The new value goes in value.
Dates accept
2026-10-24 09:30:00, a date only, an ISO date, or a number of seconds since 1970 (a number above 100,000,000).posixPermissionsis written in octal, like644or755.extensionHiddenandinvisibleaccept true, yes, 1 or on; anything else turns them off.hfsTypeCodeandhfsCreatorCodeare exactly four ASCII characters, or empty to clear.commentreplaces the Finder comment. Empty clears it.tagstakes names separated by commas or line breaks.setreplaces the tags (a tag you keep keeps its colour),addadds,removeremoves,toggleflips each one. An emptysetclears all tags.add,removeandtogglework on tags only.
A get returns the value as the step's output and puts it in into. A set returns a short description of what changed.
Parameters #
| Parameter | Type | Required | Values | What it does |
|---|---|---|---|---|
action | text | Another spelling of op. | ||
attribute | text | Which attribute to read or change. Required. An unknown name fails and lists the valid ones. | ||
into | text | The variable that receives the value, for get. | ||
name | text | Another spelling of attribute. | ||
op | text | get (the default), set, add, remove or toggle. Anything else fails. | ||
path | text | The file or folder. Required. ~ is your home folder. | ||
text | text | Another spelling of value. | ||
value | text | The new value, for the set operations. |
Every step also accepts label, onFailure, timeout and dryRunSafe.
Examples #
Read a file's size. A read changes nothing, so it is marked safe to run in a dry run:
- Get size of “hosts”
- Show “/etc/hosts is {{bytes}} bytes”
Add a tag to a file. Replace the path first, since this really changes the file:
- Add tags to “notes.txt”
Gotchas #
A missing file fails with "nothing at … to read … from" or "… to change … on".
Attributes that can be read but not changed (
size,name,fileTypeand the rest) fail onsetand list the changeable ones.Changing the group can fail; the message carries the system's reason.
A
getnever fails for an empty value. A file with no tags gives an empty text.In a dry run a
setis simulated. Agetis simulated too unless you turn on Safe in a dry run (dryRunSafe) for the step.