Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add all sub public.text #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 98 additions & 1 deletion QuickLookStephenProject/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,106 @@
<string>QLGenerator</string>
<key>LSItemContentTypes</key>
<array>
<string>public.data</string>
<string>com.apple.applescript.script</string>
<string>com.apple.applescript.text</string>
<string>com.apple.ascii-property-list</string>
<string>com.apple.audio-unit-preset</string>
<string>com.apple.chess.game</string>
<string>com.apple.chess.pgn</string>
<string>com.apple.configprofile</string>
<string>com.apple.configurationprofiles.profile</string>
<string>com.apple.crashreport</string>
<string>com.apple.device-model-code</string>
<string>com.apple.finalcutpro.colorboard</string>
<string>com.apple.finalcutpro.xml</string>
<string>com.apple.gpurestart</string>
<string>com.apple.hangreport</string>
<string>com.apple.haptics.ahap</string>
<string>com.apple.iig-source</string>
<string>com.apple.ips</string>
<string>com.apple.log</string>
<string>com.apple.mobileconfig</string>
<string>com.apple.music.metadata</string>
<string>com.apple.nspboard-type</string>
<string>com.apple.ostype</string>
<string>com.apple.panicreport</string>
<string>com.apple.preference.network</string>
<string>com.apple.provisionprofile</string>
<string>com.apple.rez-source</string>
<string>com.apple.shutdownstall</string>
<string>com.apple.spinreport</string>
<string>com.apple.symbol-export</string>
<string>com.apple.systemprofiler.document</string>
<string>com.apple.terminal.shell-script</string>
<string>com.apple.traditional-mac-plain-text</string>
<string>com.apple.tv.metadata</string>
<string>com.apple.xml-property-list</string>
<string>com.netscape.javascript-source</string>
<string>com.sun.java-source</string>
<string>com.sun.java-web-start</string>
<string>public.ada-source</string>
<string>public.assembly-source</string>
<string>public.bash-script</string>
<string>public.c-header</string>
<string>public.c-plus-plus-header</string>
<string>public.c-plus-plus-inline-header</string>
<string>public.c-plus-plus-source</string>
<string>public.c-plus-plus-source.preprocessed</string>
<string>public.c-source</string>
<string>public.c-source.preprocessed</string>
<string>public.case-insensitive-text</string>
<string>public.comma-separated-values-text</string>
<string>public.content</string>
<string>public.csh-script</string>
<string>public.css</string>
<string>public.data</string>
<string>public.delimited-values-text</string>
<string>public.dylan-source</string>
<string>public.filename-extension</string>
<string>public.fortran-77-source</string>
<string>public.fortran-90-source</string>
<string>public.fortran-95-source</string>
<string>public.fortran-source</string>
<string>public.json</string>
<string>public.ksh-script</string>
<string>public.lex-source</string>
<string>public.mig-source</string>
<string>public.mime-type</string>
<string>public.objective-c-plus-plus-source</string>
<string>public.objective-c-plus-plus-source.preprocessed</string>
<string>public.objective-c-source</string>
<string>public.objective-c-source.preprocessed</string>
<string>public.pascal-source</string>
<string>public.patch-file</string>
<string>public.perl-script</string>
<string>public.php-script</string>
<string>public.plain-text</string>
<string>public.precompiled-c-header</string>
<string>public.precompiled-c-plus-plus-header</string>
<string>public.python-script</string>
<string>public.rss</string>
<string>public.rtf</string>
<string>public.ruby-script</string>
<string>public.script</string>
<string>public.shell-script</string>
<string>public.source-code</string>
<string>public.source-code.preprocessed</string>
<string>public.swift-source</string>
<string>public.tab-separated-values-text</string>
<string>public.tcsh-script</string>
<string>public.text</string>
<string>public.unix-executable</string>
<string>public.utf16-external-plain-text</string>
<string>public.utf16-plain-text</string>
<string>public.utf8-plain-text</string>
<string>public.utf8-tab-separated-values-text</string>
<string>public.x509-printable-encoded-archive</string>
<string>public.xfd</string>
<string>public.xhtml</string>
<string>public.xml</string>
<string>public.yacc-source</string>
<string>public.yaml</string>
<string>public.zsh-script</string>
</array>
<key>LSTypeIsPackage</key>
<false/>
Expand Down
72 changes: 72 additions & 0 deletions find_text_utis.py
Original file line number Diff line number Diff line change
@@ -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<string>" + uti + "</string>")
print(len(utis))