File metadata (read, write etc)

Is it possible to change a file metadata, say the Title of a video, with any action in Keyboard maestro?

I couldn’t find anything related to metadata in the documentation, only file attributes (modified date etc).

Thank you.

I wonder if you could do something with Execute Shell Script actions ?

The shell command mdls will list metadata key/value pairs for a file so perhaps:

echo "$KMVAR_selectedFile\n\n$(mdls $KMVAR_selectedFile)"

to generate a list:

and if you are happy to experiment with such things, you should be able to set/edit a key/value pair with another shell command: xattr, prefixing the kMDItem key name with

(type man xattr at the prompt, or use this macro:

For an example of the syntax, something like:

xattr -w "Other name" ~/Desktop/someVideo.mp4

but I personally haven't experimented much with metadata, so I'm not sure if this gives you the leverage you want.

Rob – variable names need to be conformed in your example, I believe. You set “fileMetaData” in the first action but use “metaData” in the other actions.

1 Like

Thank you for spotting that – image now edited

OK thanks.

Also, the macro fails for filenames with interior spaces.

~/Desktop/History of Normandy.docx
~/Desktop/History: could not find ~/Desktop/History.

Curiously enough that’s not happening on my system with the (read) macro (the commands are flanked by double quotes), but perhaps you mean the xattr write snippet ?

There I would combine $HOME with double quoting, I think, for spaced paths, so perhaps:

xattr -w "Other name" "$HOME/Desktop/some spaced Video.mp4"

One of life's mysteries, I suppose. AFAICT my instance is the same as Rob's -- go figure.

This, however, does work

echo "$KMVAR_selectedFile"\n\n$(mdls "$KMVAR_selectedFile")

quote the variable; do not quote the entire command string

Here's a file version:

List metadata of selected file.kmmacros (3.7 KB)

That version also fails here (10.10.4 and KM 7.0). However the version I posted just above your last post works

echo "$KMVAR_selectedFile"\n\n$(mdls "$KMVAR_selectedFile")

Good ! I’ll adjust and repost.

(Though I moved the quotes slightly to get line-delimited output)

You know, this actually works best:

mdls "$KMVAR_selectedFile"

because Execute Shell Script > Save to Variable is already echoing the result. The short version gets the formatting of the output right.

Terse is best.