Last active
February 4, 2024 17:54
-
-
Save davidbalbert/2740c35896f95c968bdd67d011cb5024 to your computer and use it in GitHub Desktop.
UTType graphviz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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