Skip to content

The Eclectic Light Company

Macs, painting, and more
Main navigation
  • Downloads
  • M1 Macs
  • Mac Problems
  • Mac articles
  • Art
  • Macs
  • Painting
hoakley January 24, 2018 Macs, Technology, xattr

File types, the UTI, and even more metadata

We use URLs all the time, sometimes have to work in UTC, and occasionally stumble over UUIDs, but what is a UTI, where would you use one, and what do they have to do with metadata?

In theory, only developers, and others who enjoy life up to their neck in the alligators of macOS, should come across Apple’s Uniform Type Identifiers. But as they appear in many property lists and in the output of command tools, and are central to features such as Launch Services, it is as well to be familiar with them.

UTIs came about because of multiple systems for identifying file types in macOS. Classic Mac OS used a four-character code, the OSType, half of the Finder Info which underpinned its Desktop illusion, associating apps with documents. In that, a JPEG image file is known by the characters JPEG, unsurprisingly. But macOS also had its origins in NeXTStep, which was essentially Unix, and believed instead in file extensions such as .jpeg or .jpg. Then along came MIME (or media) types, used primarily to define content types on the internet, in email messages, and so on. Under those, that JPEG image is image/jpeg.

With three incompatible systems to choose between, Apple decided to create a fourth, the UTI. In that, the image is public.jpeg.

UTIs are an extensive, hierarchical classification system for anything you can find stored in a computer. At the top is public.item: every file, folder, bundle, etc., is a public.item. Then the naming gets progressively more specific: the image eventually works its way down to the most specific public.jpeg.

Apps have to declare the types of documents which they can read and write, something recorded in their property lists, which are in turn used by Launch Services to decide which app gets to open which type of document. Although this system still uses and respect OSTypes, extensions, and MIME types, it just loves a good UTI.

UTIs are also used with pasteboards, which are the basis for cut-copy-paste operations, drag and drop, Services, and a few other everyday bits of magic which apps perform with macOS.

The easiest way to see UTIs is using Terminal’s mdls command to list metadata, as they’re counted as being (a very important) part of every file’s metadata. The command to view just the UTI hierarchy for a file named filename is
mdls -name kMDItemContentTypeTree filename

But let’s go the whole hog and view all the metadata for a text file which I have nobbled with SearchKey so that it has five extra extended attributes. This is simple using a command like
mdls 0test.txt
and produces:
_kMDItemOwnerUserID = 501
kMDItemContentCreationDate = 2017-10-26 18:47:05 +0000
kMDItemContentModificationDate = 2017-10-26 18:47:05 +0000
kMDItemContentType = "public.plain-text"
kMDItemContentTypeTree = ("public.plain-text", "public.item", "public.text", "public.data", "public.content", "public.plain-text")
kMDItemCopyright = "Copyright © 2018 EHN & DIJ Oakley"
kMDItemCreator = "Howard Oakley"
kMDItemDateAdded = 2018-01-21 20:03:00 +0000
kMDItemDescription = "This is just a test file of sorts."
kMDItemDisplayName = "0test.txt"
kMDItemFSContentChangeDate = 2017-10-26 18:47:05 +0000
kMDItemFSCreationDate = 2017-10-26 18:47:05 +0000
kMDItemFSCreatorCode = ""
kMDItemFSFinderFlags = 0
kMDItemFSHasCustomIcon = (null)
kMDItemFSInvisible = 0
kMDItemFSIsExtensionHidden = 0
kMDItemFSIsStationery = (null)
kMDItemFSLabel = 0
kMDItemFSName = "0test.txt"
kMDItemFSNodeCount = (null)
kMDItemFSOwnerGroupID = 20
kMDItemFSOwnerUserID = 501
kMDItemFSSize = 391
kMDItemFSTypeCode = ""
kMDItemHeadline = "The News Headlines 3"
kMDItemKeywords = ("key; lock; padlock; chain; safe")
kMDItemKind = "Plain Text Document"
kMDItemLastUsedDate = 2018-01-22 09:46:51 +0000
kMDItemLogicalSize = 391
kMDItemPhysicalSize = 4096
kMDItemUseCount = 45
kMDItemUsedDates = ("2018-01-21 00:00:00 +0000", "2018-01-22 00:00:00 +0000")

If you now change the extension of that file to .png and repeat the command, you have changed some of those metadata. macOS thinks that’s a PNG image file, so the UTIs have changed to reflect that:
kMDItemContentType = "public.png"
kMDItemContentTypeTree = ("public.item", "public.png", "public.data", "public.image", "public.content")
kMDItemKind = "Portable Network Graphics image"

mdls is one of a group of commands which work with metadata in its broadest sense. Also worth knowing are mdfind, which searches the metadata store and returns a list of files satisfying a query, and mdutil, which controls metadata stores on each volume, and can for example force them to be rebuilt. Those are quite complex if not awesome commands which are best left to their man pages.

Hopefully this helps explain how file typing, metadata, Launch Services, and the amazing illusions created by macOS all hold together. If you want to read more, Apple provides a Uniform Type Identifiers Overview, and a UTI Reference with all the gory details.

Oh, and for those of you who thought that UTI stands for urinary tract infection, keep drinking plenty of fluids.

Share this:

  • Twitter
  • Facebook
  • Reddit
  • Pinterest
  • Email
  • Print

Like this:

Like Loading...

Related

Posted in Macs, Technology, xattr and tagged extensions, files, Finder, LaunchServices, macOS, mdfind, mdls, mdutil, metadata, MIME, pasteboard, UTI. Bookmark the permalink.

Quick Links

  • Downloads
  • Mac Troubleshooting Summary
  • M1 Macs
  • Mac problem-solving
  • Painting topics
  • Painting
  • Long Reads

Search

Monthly archives

  • January 2021 (56)
  • December 2020 (77)
  • November 2020 (84)
  • October 2020 (81)
  • September 2020 (79)
  • August 2020 (103)
  • July 2020 (81)
  • June 2020 (78)
  • May 2020 (78)
  • April 2020 (81)
  • March 2020 (86)
  • February 2020 (77)
  • January 2020 (86)
  • December 2019 (82)
  • November 2019 (74)
  • October 2019 (89)
  • September 2019 (80)
  • August 2019 (91)
  • July 2019 (95)
  • June 2019 (88)
  • May 2019 (91)
  • April 2019 (79)
  • March 2019 (78)
  • February 2019 (71)
  • January 2019 (69)
  • December 2018 (79)
  • November 2018 (71)
  • October 2018 (78)
  • September 2018 (76)
  • August 2018 (78)
  • July 2018 (76)
  • June 2018 (77)
  • May 2018 (71)
  • April 2018 (67)
  • March 2018 (73)
  • February 2018 (67)
  • January 2018 (83)
  • December 2017 (94)
  • November 2017 (73)
  • October 2017 (86)
  • September 2017 (92)
  • August 2017 (69)
  • July 2017 (81)
  • June 2017 (76)
  • May 2017 (90)
  • April 2017 (76)
  • March 2017 (79)
  • February 2017 (65)
  • January 2017 (76)
  • December 2016 (75)
  • November 2016 (68)
  • October 2016 (76)
  • September 2016 (78)
  • August 2016 (70)
  • July 2016 (74)
  • June 2016 (66)
  • May 2016 (71)
  • April 2016 (67)
  • March 2016 (71)
  • February 2016 (68)
  • January 2016 (90)
  • December 2015 (96)
  • November 2015 (103)
  • October 2015 (119)
  • September 2015 (115)
  • August 2015 (117)
  • July 2015 (117)
  • June 2015 (105)
  • May 2015 (111)
  • April 2015 (119)
  • March 2015 (69)
  • February 2015 (54)
  • January 2015 (39)

Tags

Adobe APFS Apple AppleScript App Store backup Big Sur Blake Bonnard bug bugs Catalina Consolation Console diagnosis Disk Utility Doré El Capitan extended attributes Finder firmware Gatekeeper Gérôme HFS+ High Sierra history history of painting iCloud Impressionism iOS landscape LockRattler log logs Mac Mac history macOS macOS 10.12 macOS 10.13 macOS 10.14 macOS 10.15 macOS 11 malware Metamorphoses Mojave Monet Moreau MRT myth narrative naturalism OS X Ovid painting Pissarro Poussin privacy realism riddle Rubens Sargent scripting security Sierra Swift symbolism Time Machine Turner update upgrade van Gogh vulnerability xattr Xcode XProtect

Statistics

  • 7,550,680 hits
Blog at WordPress.com.
Footer navigation
  • About & Contact
  • Macs
  • Painting
  • Language
  • Tech
  • Life
  • General
  • Downloads
  • Mac problem-solving
  • Extended attributes (xattrs)
  • Painting topics
  • Hieronymus Bosch
  • English language
  • LockRattler: 10.12 Sierra
  • LockRattler: 10.13 High Sierra
  • LockRattler: 10.11 El Capitan
  • Updates: El Capitan
  • Updates: Sierra, High Sierra, Mojave, Catalina, Big Sur
  • LockRattler: 10.14 Mojave
  • SilentKnight, silnite, LockRattler, SystHist & Scrub
  • DelightEd & Podofyllin
  • xattred, Metamer, Sandstrip & xattr tools
  • 32-bitCheck & ArchiChect
  • T2M2, Ulbow, Consolation and log utilities
  • Cirrus & Bailiff
  • Taccy, Signet, Precize, Alifix, UTIutility, alisma
  • Revisionist & DeepTools
  • Text Utilities: Nalaprop, Dystextia and others
  • PDF
  • Keychains & Permissions
  • LockRattler: 10.15 Catalina
  • Updates
  • Spundle, Cormorant, Stibium, Dintch, Fintch and cintch
  • Long Reads
  • LockRattler: 11.0 Big Sur
  • Mac Troubleshooting Summary
  • M1 Macs
Secondary navigation
  • Search

Post navigation

What is in the High Sierra 10.13.3 update?
What is in the Sierra Security Update 2018-001?

Begin typing your search above and press return to search. Press Esc to cancel.

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.
%d bloggers like this: