In this post I’d like to share with you a quick tip on how to get a file’s universal type identifier and other metadata on macOS using terminal.
With the introduction of Spotlight on Mac OS X v10.4 Apple also added a few command line tools for querying and manipulating indexes created by Spotlight. Among them is mdls, a utility that, as its man page states, “lists the metadata attributes for the specified file”. These metadata attributes include a file’s UTI and UTI inheritance hierarchy.
Using mdls is pretty straightforward:
1 |
mdls /path/to/your/file.txt |
It will print out a whole bunch of stuff and kMDItemContentType and kMDItemContentTypeTree are your file’s UTI and UTI inheritance hierarchy:
1 2 3 4 5 6 7 8 |
kMDItemContentType = "public.plain-text" kMDItemContentTypeTree = ( "public.item", "public.text", "public.data", "public.content", "public.plain-text" ) |
That’s it for now. I hope this helps someone.
Happy coding!