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.
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 com.apple.metadata
(type man xattr
at the Terminal.app prompt, or use this macro: http://forum.keyboardmaestro.com/t/generate-a-pdf-copy-of-the-man-page-for-a-shell-command/1308)
For an example of the syntax, something like:
xattr -w com.apple.metadata:kMDItemDisplayName "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.
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 com.apple.metadata:kMDItemDisplayName "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
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.