Skip to content

Instantly share code, notes, and snippets.

@davidbalbert
Last active February 4, 2024 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidbalbert/2740c35896f95c968bdd67d011cb5024 to your computer and use it in GitHub Desktop.
Save davidbalbert/2740c35896f95c968bdd67d011cb5024 to your computer and use it in GitHub Desktop.
UTType graphviz
import UniformTypeIdentifiers
// As of macOS 14.3
extension UTType {
static var allTypes: [UTType] {
[
.item,
.content,
.compositeContent,
.diskImage,
.data,
.directory,
.resolvable,
.symbolicLink,
.executable,
.mountPoint,
.aliasFile,
.urlBookmarkData,
.url,
.fileURL,
.text,
.plainText,
.utf8PlainText,
.utf16ExternalPlainText,
.utf16PlainText,
.delimitedText,
.commaSeparatedText,
.tabSeparatedText,
.utf8TabSeparatedText,
.rtf,
.html,
.xml,
.yaml,
.sourceCode,
.assemblyLanguageSource,
.cSource,
.objectiveCSource,
.swiftSource,
.cPlusPlusSource,
.objectiveCPlusPlusSource,
.cHeader,
.cPlusPlusHeader,
.script,
.appleScript,
.osaScript,
.osaScriptBundle,
.javaScript,
.shellScript,
.perlScript,
.pythonScript,
.rubyScript,
.phpScript,
.makefile,
.json,
.propertyList,
.xmlPropertyList,
.binaryPropertyList,
.pdf,
.rtfd,
.flatRTFD,
.webArchive,
.image,
.jpeg,
.tiff,
.gif,
.png,
.icns,
.bmp,
.ico,
.rawImage,
.svg,
.livePhoto,
.heif,
.heic,
.webP,
.threeDContent,
.usd,
.usdz,
.realityFile,
.sceneKitScene,
.arReferenceObject,
.audiovisualContent,
.movie,
.video,
.audio,
.quickTimeMovie,
.mpeg,
.mpeg2Video,
.mpeg2TransportStream,
.mp3,
.mpeg4Movie,
.mpeg4Audio,
.appleProtectedMPEG4Audio,
.appleProtectedMPEG4Video,
.avi,
.aiff,
.wav,
.midi,
.playlist,
.m3uPlaylist,
.folder,
.volume,
.package,
.bundle,
.pluginBundle,
.spotlightImporter,
.quickLookGenerator,
.xpcService,
.framework,
.application,
.applicationBundle,
.applicationExtension,
.unixExecutable,
.exe,
.systemPreferencesPane,
.archive,
.gzip,
.bz2,
.zip,
.appleArchive,
.spreadsheet,
.presentation,
.database,
.message,
.contact,
.vCard,
.toDoItem,
.calendarEvent,
.emailMessage,
.internetLocation,
.internetShortcut,
.font,
.bookmark,
.pkcs12,
.x509Certificate,
.epub,
.log,
.ahap
]
}
}
func escape(identifier: String) -> String {
identifier.replacingOccurrences(of: ".", with: "\\.")
}
func dot(root baseType: UTType) -> String {
var graph = "digraph UTTypeHierarchy {\n"
graph += " node [shape=box];\n"
func addDescendants(of type: UTType) {
for childType in UTType.allTypes where childType.supertypes.contains(type) {
graph += " \"\(escape(identifier: type.identifier))\" -> \"\(escape(identifier: childType.identifier))\";\n"
addDescendants(of: childType)
}
}
addDescendants(of: baseType)
graph += "}"
return graph
}
print(dot(root: .data))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment