Browse the docs

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 Link or Alias), contentType (a type identifier such as public.plain-text), contentKind (the Finder's description).

  • Dates, as yyyy-MM-dd HH:mm:ss text 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, like 644), extensionHidden and invisible (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).

  • posixPermissions is written in octal, like 644 or 755.

  • extensionHidden and invisible accept true, yes, 1 or on; anything else turns them off.

  • hfsTypeCode and hfsCreatorCode are exactly four ASCII characters, or empty to clear.

  • comment replaces the Finder comment. Empty clears it.

  • tags takes names separated by commas or line breaks. set replaces the tags (a tag you keep keeps its colour), add adds, remove removes, toggle flips each one. An empty set clears all tags. add, remove and toggle work 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 #

ParameterTypeRequiredValuesWhat it does
actiontextAnother spelling of op.
attributetextWhich attribute to read or change. Required. An unknown name fails and lists the valid ones.
intotextThe variable that receives the value, for get.
nametextAnother spelling of attribute.
optextget (the default), set, add, remove or toggle. Anything else fails.
pathtextThe file or folder. Required. ~ is your home folder.
texttextAnother spelling of value.
valuetextThe 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:

Show the size of /etc/hosts
Do
  1. Get size of “hosts”
  2. Show “/etc/hosts is {{bytes}} bytes”
Open in Switchboard to try it

Add a tag to a file. Replace the path first, since this really changes the file:

Tag a file (really changes its tags)
Do
  1. Add tags to “notes.txt”
Open in Switchboard to try it

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, fileType and the rest) fail on set and list the changeable ones.

  • Changing the group can fail; the message carries the system's reason.

  • A get never fails for an empty value. A file with no tags gives an empty text.

  • In a dry run a set is simulated. A get is simulated too unless you turn on Safe in a dry run (dryRunSafe) for the step.

See also #

File operation, Split path