From e15eab28cd7caa7daa0cb3d2677b97fdd8141632 Mon Sep 17 00:00:00 2001 From: "Mr. Pennyworth" Date: Fri, 23 Feb 2024 09:30:22 -0600 Subject: [PATCH] Handle dicts without `CFBundleDisplayName` in their info.plist There seem to be dictionaries whose `info.plist` does not contain the property `CFBundleDisplayName`. I wasn't able to reproduce the issue locally because all the dictionaries Apple allows me to enable on my laptop do contain that property. Based on #9, it looks like these problematic dictionaries do have the `CFBundleName` property. To handle such such dictionaries, in this change, we introduce a fallback order: - `CFBundleDisplayName` - `CFBundleName` - `CFBundleIdentifier` We also make sure that if a dictionary doesn't have any of the above attributes, we ignore the dictionary, log the error, but do not fail `.dict-import`. Fixes #9 --- info.plist | 2 +- pyapp/BetterDict.py | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/info.plist b/info.plist index 53837e8..6d2d784 100644 --- a/info.plist +++ b/info.plist @@ -938,7 +938,7 @@ Subsequent searches should be snappy variablesdontexport version - 0.2.5 + 0.2.6 webaddress https://github.com/mr-pennyworth/alfred-better-dictionaries diff --git a/pyapp/BetterDict.py b/pyapp/BetterDict.py index c76bdb2..7e19de4 100644 --- a/pyapp/BetterDict.py +++ b/pyapp/BetterDict.py @@ -241,7 +241,13 @@ def get_dict_id(info): def get_dict_name(info): - return info['CFBundleDisplayName'] + return info.get( + 'CFBundleDisplayName', + info.get( + 'CFBundleName', + info['CFBundleIdentifier'], + ) + ) def create_workflow_objects(dict_name, dict_id): @@ -390,14 +396,17 @@ def list_unimported_dicts(import_base_dir): imported = [i['title'] for i in json.load(f)['items']] for dict_path in all_dict_paths(): - info = dict_info(dict_path) - dict_name = get_dict_name(info) - if dict_name in imported: - continue - alfreditems['items'].append({ - 'title': dict_name, - 'arg': dict_path - }) + try: + info = dict_info(dict_path) + dict_name = get_dict_name(info) + if dict_name in imported: + continue + alfreditems['items'].append({ + 'title': dict_name, + 'arg': dict_path + }) + except Exception as e: + print(f'Unable to process "{dict_path}": {e}', file=sys.stderr) print(json.dumps(alfreditems, indent=2))