How to get the UTI of any file on macOS

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:

It will print out a whole bunch of stuff and kMDItemContentType and kMDItemContentTypeTree are your file’s UTI and UTI inheritance hierarchy:

That’s it for now. I hope this helps someone.

Happy coding!

Leave a Reply

Your email address will not be published. Required fields are marked *