Skip to content

Commit

Permalink
Handle dicts without CFBundleDisplayName in their info.plist
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mr-pennyworth committed Feb 23, 2024
1 parent 4d48574 commit e15eab2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ Subsequent searches should be snappy
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>0.2.5</string>
<string>0.2.6</string>
<key>webaddress</key>
<string>https://github.com/mr-pennyworth/alfred-better-dictionaries</string>
</dict>
Expand Down
27 changes: 18 additions & 9 deletions pyapp/BetterDict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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))


Expand Down

0 comments on commit e15eab2

Please sign in to comment.