From d8a9a8b9b0d0b91cfde6759f4e6eb13bbd279da1 Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Sun, 18 Oct 2020 23:36:36 +0530 Subject: [PATCH] Add all sub public.text --- QuickLookStephenProject/Info.plist | 99 +++++++++++++++++++++++++++++- find_text_utis.py | 72 ++++++++++++++++++++++ 2 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 find_text_utis.py diff --git a/QuickLookStephenProject/Info.plist b/QuickLookStephenProject/Info.plist index 51c416a..f8f7578 100644 --- a/QuickLookStephenProject/Info.plist +++ b/QuickLookStephenProject/Info.plist @@ -13,9 +13,106 @@ QLGenerator LSItemContentTypes - public.data + com.apple.applescript.script + com.apple.applescript.text + com.apple.ascii-property-list + com.apple.audio-unit-preset + com.apple.chess.game + com.apple.chess.pgn + com.apple.configprofile + com.apple.configurationprofiles.profile + com.apple.crashreport + com.apple.device-model-code + com.apple.finalcutpro.colorboard + com.apple.finalcutpro.xml + com.apple.gpurestart + com.apple.hangreport + com.apple.haptics.ahap + com.apple.iig-source + com.apple.ips + com.apple.log + com.apple.mobileconfig + com.apple.music.metadata + com.apple.nspboard-type + com.apple.ostype + com.apple.panicreport + com.apple.preference.network + com.apple.provisionprofile + com.apple.rez-source + com.apple.shutdownstall + com.apple.spinreport + com.apple.symbol-export + com.apple.systemprofiler.document + com.apple.terminal.shell-script + com.apple.traditional-mac-plain-text + com.apple.tv.metadata + com.apple.xml-property-list + com.netscape.javascript-source + com.sun.java-source + com.sun.java-web-start + public.ada-source + public.assembly-source + public.bash-script + public.c-header + public.c-plus-plus-header + public.c-plus-plus-inline-header + public.c-plus-plus-source + public.c-plus-plus-source.preprocessed + public.c-source + public.c-source.preprocessed + public.case-insensitive-text + public.comma-separated-values-text public.content + public.csh-script + public.css + public.data + public.delimited-values-text + public.dylan-source + public.filename-extension + public.fortran-77-source + public.fortran-90-source + public.fortran-95-source + public.fortran-source + public.json + public.ksh-script + public.lex-source + public.mig-source + public.mime-type + public.objective-c-plus-plus-source + public.objective-c-plus-plus-source.preprocessed + public.objective-c-source + public.objective-c-source.preprocessed + public.pascal-source + public.patch-file + public.perl-script + public.php-script + public.plain-text + public.precompiled-c-header + public.precompiled-c-plus-plus-header + public.python-script + public.rss + public.rtf + public.ruby-script + public.script + public.shell-script + public.source-code + public.source-code.preprocessed + public.swift-source + public.tab-separated-values-text + public.tcsh-script + public.text public.unix-executable + public.utf16-external-plain-text + public.utf16-plain-text + public.utf8-plain-text + public.utf8-tab-separated-values-text + public.x509-printable-encoded-archive + public.xfd + public.xhtml + public.xml + public.yacc-source + public.yaml + public.zsh-script LSTypeIsPackage diff --git a/find_text_utis.py b/find_text_utis.py new file mode 100644 index 0000000..6b07d23 --- /dev/null +++ b/find_text_utis.py @@ -0,0 +1,72 @@ +"""Script to find all utis & sub-utis conforming to public.text .""" +import os +from itertools import groupby + +LSREGISTER = "/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Versions/Current/Support/lsregister" +SEPARATOR = ( + "--------------------------------------------------------------------------------" +) +EXCEPTIONS = [ + "com.apple.mach-o-binary", + "com.apple.structured-text", + "public.3d-content", + "public.calendar-event", + "public.contact", + "public.html", + "public.image", + "public.movie", + "public.playlist", +] + + +def add_keys_recursively(dict, list, key): + """Add values & sub-values from dict of lists, recursively.""" + if key in dict: + for val in dict[key]: + list.append(val) + add_keys_recursively(dict, list, val) + + +os.system(LSREGISTER + " -dump > /tmp/out.txt") +with open("/tmp/out.txt") as f: + dump = list( + list(g) for _, g in groupby(f.read().splitlines(), key=SEPARATOR.__ne__) + )[::2] + +entities = [] +for lines in dump[1:]: + entity = {} + last = None + for line in lines: + data = line.split(":", 1) + if len(data) == 1: + entity[last] += data[0] + else: + entity[data[0]] = data[1] + last = data[0] + if "uti" in entity and "conforms to" in entity: + name = entity["uti"].strip() + type = [x.strip() for x in entity["conforms to"].split(",")] + if name in EXCEPTIONS or any(x in type for x in EXCEPTIONS): + continue + entities.append({"name": name, "type": type}) + +conformed_by = {} +for entity in entities: + for item in entity["type"]: + if item not in conformed_by: + conformed_by[item] = set() + conformed_by[item].add(entity["name"]) + +utis = [ + "public.content", + "public.data", + "public.text", + "public.unix-executable", +] +add_keys_recursively(conformed_by, utis, "public.text") +add_keys_recursively(conformed_by, utis, "public.unix-executable") + +for uti in sorted(set(utis)): + print("\t\t\t\t" + uti + "") +print(len(utis))