Skip to content

Instantly share code, notes, and snippets.

@vitorgalvao
Created August 4, 2024 17:47
Show Gist options
  • Save vitorgalvao/ce10d7fc5a295e6187cc4bfca0030cb3 to your computer and use it in GitHub Desktop.
Save vitorgalvao/ce10d7fc5a295e6187cc4bfca0030cb3 to your computer and use it in GitHub Desktop.
Use JavaScript for Automation (JXA) to parse an app plist and return the document and URL information it registers.
// Function to parse plist for the information we want
function documentTypes(infoPlist) {
const plistJSON = Application("System Events").propertyListFiles.byName(infoPlist).contents.value()
const getEntries = (parentKey, childKey) => plistJSON[parentKey]?.flatMap(item => item[childKey] || []) || []
return {
Extensions: getEntries("CFBundleDocumentTypes", "CFBundleTypeExtensions"),
ItemContentTypes: getEntries("CFBundleDocumentTypes", "LSItemContentTypes"),
MIMETypes: getEntries("CFBundleDocumentTypes", "CFBundleTypeMIMETypes"),
URLSchemes: getEntries("CFBundleURLTypes", "CFBundleURLSchemes"),
UTTypeIdentifiers: getEntries("UTImportedTypeDeclarations", "UTTypeIdentifier")
}
}
// Run it in Safari
documentTypes("/Applications/Safari.app/Contents/Info.plist")
// {
// "Extensions":["css", "pdf", "webarchive", "webbookmark", "webhistory", "webloc", "download", "safariextz", "gif", "html", "htm", "shtml", "jhtml", "js", "jpg", "jpeg", "jp2", "txt", "text", "png", "tiff", "tif", "url", "ico", "xhtml", "xht", "xhtm", "xht", "xml", "xbl", "xsl", "xslt", "svg", "avif", "webp", "heic", "jxl"],
// "ItemContentTypes":[],
// "MIMETypes":["text/css", "application/pdf", "application/x-webarchive", "application/x-safari-extension", "image/gif", "text/html", "application/x-javascript", "image/jpeg", "image/jp2", "text/plain", "image/png", "image/tiff", "image/x-icon", "application/xhtml+xml", "application/xml", "text/xml", "image/svg+xml", "image/avif", "image/webp", "image/heic", "image/jxl"],
// "URLSchemes":["http", "https", "file", "x-safari-https", "prefs", "x-webkit-app-launch"],
// "UTTypeIdentifiers":[]
// }
// Run it in QuickTime Player
documentTypes("/System/Applications/QuickTime Player.app/Contents/Info.plist")
// {
// "Extensions":[],
// "ItemContentTypes":["com.apple.quicktimeplayerx-composition", "com.apple.quicktimeplayerx-composition-bundle", "public.avchd-content", "public.avchd-collection", "public.audiovisual-content", "public.audio", "public.mpeg-4-audio", "com.apple.protected-mpeg-4-audio", "public.mp3", "public.ulaw-audio", "public.au-audio", "public.aifc-audio", "public.aiff-audio", "com.apple.coreaudio-format", "org.3gpp.adaptive-multi-rate-audio", "com.digidesign.sd2-audio", "com.microsoft.waveform-audio", "public.movie", "com.apple.quicktime-movie", "public.mpeg", "public.mpeg-2-video", "public.mpeg-4", "com.apple.protected-mpeg-4-video", "public.dv-movie", "public.avi", "public.flc-animation", "public.3gpp", "public.3gpp2", "com.apple.photos.apple-adjustment-envelope", "com.apple.photos.slow-motion-video-sidecar", "public.camera-raw-image", "public.jpeg", "public.png", "public.tiff", "public.heif", "public.folder", "com.apple.mediaextension-content", "com.apple.avurlasset-content"],
// "MIMETypes":[],
// "URLSchemes":[],
// "UTTypeIdentifiers":["public.sdp", "public.avchd-content", "public.avchd-mpeg-2-transport-stream", "com.apple.photos.apple-adjustment-envelope", "com.apple.photos.slow-motion-video-sidecar"]
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment