Jump to content

Recommended Posts

Better Dictionaries


Better search and live previews for built-in macOS dictionaries.

 

This post might be outdated, link to up-to-date README
Download the latest version: Better.Dictionaries.alfredworkflow


Features

  • IPA (phonetic) pronunciations:
    Press ⌘↩ to hear the pronunciation.
  • In-Alfred live previews with colors that
    automatically adapt to Alfred's theme:
    auto-theme.png
  • Reverse search:
    reverse-search.png
  • More relevant search results:  
    left: macOS/Alfred built-in search, right: BetterDict
    built-in-vs-workflow.png
  • If one word has multiple, unrelated meanings with different
    origin, they are showed as diffrent entries
    (in the above example, see "arm" has two entries at the top)
  • Import any compatible dictionary


Setup


After importing the workflow,
first type .setup-better-dictionaries into Alfred
and follow the instructions for granting permissions.


Importing a Dictionary


After setup, type .dict-import into Alfred.
import-any.png
Select the dictionary you want to import.  


Dictionary-specific Keywords and Hotkeys


After a dictionary is imported, a script filter and a hotkey trigger
is automatically created into the workflow editor. 

  • Freshly-installed workflow without any imported dictionaries:
    before-import.png
  • Two hotkeys and keyword triggers each automatically added after importing
    two dictionaries. They come pre-labeled with dictionary names:
    after-import.png
  • This allows you to assign hotkeys and keywords for specific dictionaries.
    For example, below you can see how I have manually assigned keywords
    thesaurus and defn to the thesaurus and dictionary respectively.
    In addition, I can trigger the dictionary search using ⌃⌥⌘D.  


Word Lookup


You can use the hotkeys/keywords created above for directly searhcing
specific dictionaries. That's the recommended way for dictionaries
that you use frequently.


For the infrequently used dictionaries for which you haven't assigned
any hotkeys/keywords, follow this:
 1. Type lookup into Alfred. You'll see a list of all dictionaries
    imported into BetterDict.
    lookup-imported.png
 2. Select the dictionary to search, and type the search query.


Notes and Warnings

  • [*]Importing a dictionary could take as much as 30 minutes
    on old machines or if there's significant CPU activity from other apps.[*]After each mac restart, for the first time when you run
    the workflow, expect a comparatively slower search.
    Subsequent searches should be instant.[*]This workflow takes a LOT of space on disk. Take a look at the comparison:

     

# Built-in dictionaries
Oxford Thesaurus:   7 MB
Oxford Dictionary: 36 MB


# After importing into BetterDict
Oxford Thesaurus:     101 MB (html files)
Oxford Dictionary:    442 MB (html files)
Search index for two: 730 MB (apart from html)


 

Known Issues
  • The workflow doeesn't work if the theme is Alfred Classic.  
    If you must use that theme, duplicate that theme and use the
    duplicated one.
Edited by Mr Pennyworth
Link to comment
Quote

Works like a charm. Except for one thing, I don't use arrow keys to navigate, but ctrl + n or ctrl + p, the right side pane won't respond to those keys ...

Thanks @dunce for pointing that out! :)
I had no idea about those shortcuts. They sure are handy! Definitely better than the arrow keys!

 

I updated the workflow to incorporate ctrl+p and ctrl+n.
(Use the same link in the main post)

Edited by Mr Pennyworth
Link to comment

@Nrevi Thesaurus is a good idea!

I updated the workflow. Now, in the main search, results from the thesaurus show up too (they are not very highly ranked though, and this ranking is something I don't really know how to control well).

 

Also, added another keyword "thesaurus" which will exclusively search in the thesaurus.
So, if the thesaurus result doesn't show up in the main search (because the ranking algorithm somehow finds not very useful), you can this keyword instead.

 

(Download it from the link in the main post)

Edited by Mr Pennyworth
Link to comment

Hi Mr. Pennyworth,

I installed workflow and tried to use it but nothing showed. Below is the debug message I got. Could you please take a look? My OS is 11.0.1. Thank you.

 

[22:31:27.196] Logging Started...
[22:31:32.743] Better English Dictionary[Script Filter] Queuing argument 'a'
[22:31:32.979] Better English Dictionary[Script Filter] Queuing argument 'ar'
[22:31:33.204] Better English Dictionary[Script Filter] Queuing argument 'arm'
[22:31:33.806] Better English Dictionary[Script Filter] Script with argv 'arm' finished
[22:31:33.808] ERROR: Better English Dictionary[Script Filter] Code 1: % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  2746  100  2720  100    26   664k   6500 --:--:-- --:--:-- --:--:--  670k
Traceback (most recent call last):
  File "AlfredExtraPane.app/Contents/Resources/scripts/alfred-extra-pane", line 63, in <module>
    'maxVisibleResults': alfred.max_visible_results()
  File "/Users/rcl/OneDrive/Alfred.alfredpreferences/workflows/user.workflow.4AB6641D-4BFA-4427-959F-7EF9A70355D4/AlfredExtraPane.app/Contents/Resources/scripts/alfred.py", line 27, in cached_func
    cache[args] = func(*args)
  File "/Users/rcl/OneDrive/Alfred.alfredpreferences/workflows/user.workflow.4AB6641D-4BFA-4427-959F-7EF9A70355D4/AlfredExtraPane.app/Contents/Resources/scripts/alfred.py", line 264, in max_visible_results
    return plist.read(APPEARANCE_PREFS).get('visibleresults', 8) + 1
  File "/Users/rcl/OneDrive/Alfred.alfredpreferences/workflows/user.workflow.4AB6641D-4BFA-4427-959F-7EF9A70355D4/AlfredExtraPane.app/Contents/Resources/scripts/plist.py", line 16, in read
    with open(json_filepath) as jf:
IOError: [Errno 2] No such file or directory: '/tmp/e0f63736-9ab5-4d11-8321-3160108b4e2a'
[22:31:33.810] Better English Dictionary[Script Filter] /Users/rcl/OneDrive/Alfred.alfredpreferences/preferences/appearance/options/prefs.plist: file does not exist or is not readable or is not a regular file (Error Domain=NSCocoaErrorDomain Code=260 "The file “prefs.plist” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Users/rcl/OneDrive/Alfred.alfredpreferences/preferences/appearance/options/prefs.plist, NSUnderlyingError=0x7fb4f3405490 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}})
[22:31:33.811] ERROR: Better English Dictionary[Script Filter] JSON error: JSON text did not start with array or object and option to allow fragments not set. in JSON:
/Users/rcl/OneDrive/Alfred.alfredpreferences/preferences/appearance/options/prefs.plist: file does not exist or is not readable or is not a regular file (Error Domain=NSCocoaErrorDomain Code=260 "The file “prefs.plist” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Users/rcl/OneDrive/Alfred.alfredpreferences/preferences/appearance/options/prefs.plist, NSUnderlyingError=0x7fb4f3405490 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}})

Link to comment
1 minute ago, Mr Pennyworth said:

@Pinuz, does it happen only when you search for the first time or does it happen all the time?
Also, could you describe your screen setup?

This happens all the time, if and only if I have the second screen connected.
I have a Retina 2880 x 1800 screen on the right and a 1600 x 900 external screen on the left.

Link to comment

@Pinuz, I don't have a multi-monitor setup, so a bit difficult to test it out.
I have a suspicion what the bug might be, but can't verify for sure.

 

Can you help me out?

  1. Open the workflow directory in finder:image.png.939d6bc9fbe977d64953889b1747f351.png
  2. Run in terminal: killall AlfredExtraPane
  3. Download the modified AlfredExtraPane.app, extract it, and replace the one already present with the downloaded one.
  4. Run .setup-better-english-dictionary
  5. See if the issue is solved by doing a dictionary search or whether it still misbehaves.
Link to comment
4 hours ago, majjoha said:

What would it take for me to allow the workflow to search other dictionaries (in my case, Danish)?

@majjoha: is the Danish dictionary available in Dictionary.app that comes with macOS?
If yes, I'm working on the next version of this workflow, where you will be able to use any dictionary that's available in Dictionary.app. If not, I'm sorry, but there's no easy way for me to add support. However, if you are a programmer, you could look at the code and see if you can re-use any of it.

Link to comment
1 hour ago, Mr Pennyworth said:

@Pinuz, I don't have a multi-monitor setup, so a bit difficult to test it out.
I have a suspicion what the bug might be, but can't verify for sure.

 

Can you help me out?

  1. Open the workflow directory in finder:image.png.939d6bc9fbe977d64953889b1747f351.png
  2. Run in terminal: killall AlfredExtraPane
  3. Download the modified AlfredExtraPane.app, extract it, and replace the one already present with the downloaded one.
  4. Run .setup-better-english-dictionary
  5. See if the issue is solved by doing a dictionary search or whether it still misbehaves.

 

Thank you for trying to solve this :) Unfortunately, the bug is still there.

Link to comment

After installing the new update

 

[15:35:25.968] Better English Dictionary[Script Filter] Script with argv 'osten' finished
[15:35:25.983] ERROR: Better English Dictionary[Script Filter] Code 1: % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  3039  100  3011  100    28  1470k  14000 --:--:-- --:--:-- --:--:-- 1483k
Traceback (most recent call last):
  File "AlfredExtraPane.app/Contents/Resources/scripts/alfred-extra-pane", line 63, in <module>
    'maxVisibleResults': alfred.max_visible_results()
  File "/Users/d/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.F62C7F6B-69FA-45AA-873D-F4BEF67F4B96/AlfredExtraPane.app/Contents/Resources/scripts/alfred.py", line 27, in cached_func
    cache[args] = func(*args)
  File "/Users/d/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.F62C7F6B-69FA-45AA-873D-F4BEF67F4B96/AlfredExtraPane.app/Contents/Resources/scripts/alfred.py", line 265, in max_visible_results
    return readPlist(APPEARANCE_PREFS).get('visibleresults', 8) + 1
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plistlib.py", line 78, in readPlist
    rootObject = p.parse(pathOrFile)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plistlib.py", line 406, in parse
    parser.ParseFile(fileobj)
xml.parsers.expat.ExpatError: no element found: line 1, column 0

Link to comment
On 11/22/2020 at 1:06 PM, Mr Pennyworth said:

@majjoha: is the Danish dictionary available in Dictionary.app that comes with macOS?
If yes, I'm working on the next version of this workflow, where you will be able to use any dictionary that's available in Dictionary.app. If not, I'm sorry, but there's no easy way for me to add support. However, if you are a programmer, you could look at the code and see if you can re-use any of it.

Yes. It is one of the supported dictionaries, so I'll be looking for to the next version of the plugin then. Thank you once again for your hard work. I greatly appreciate it!

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...