DEV Community

MarcusZ
MarcusZ

Posted on

Alfred better dictionary

What is Alfred?

For those who have never heard of Alfred, it is an app for macOS which boosts your efficiency with hotkeys, keywords, text expansion, and more. Alfred does come with a free tier, but you might consider upgrading to their powerpack if you find the additional features useful. In this article, I am going to share with you the default workflow Alfred has for looking up definitions of words and the little workflow I created to make the experience a little better.

Disclaimer: You need the powerpack to use some of the Alfred features I am using.

Alfred Dictionary

Before we move on to the little workflow I have created, let's take a quick look at the default one. Alfred has an amazing integration with the Macbook built-in dictionaries for which I can easily toggle Alfred and type in the keyword define (this is customizable as well) follow with the word I want to search for. Here is a screenshot on what it looks like when I try to look up the definition for the word amazing:

image.png

Now, if I click Enter, it will actually open up the dictionary app with the word amazing prefilled to the search field. This does make looking up definitions easier because I no longer have to open up my browser and google for the definitions. But, could it be better?

Alfred Better Dictionary?

By better, I mean it will be great to have a preview of the definitions instead of having to open the dictionary app to see the full definitions. Of course, I am not the only one asking this question. A quick google search gave me a list of results of people asking similar questions on Alfred forum and also Reddit thread. After doing some research, there is a workflow created by mr-pennyworth which do just that. I gave the workflow a try, and it did work, but I am not a fan of having to import the dictionaries into HTML files. So, I did not stop here, the search for a better dictionary continues. Unfortunately, I couldn't find any other alternatives that could meet my need, until I learn about Alfred QuickLook. So what QuickLook can do is, if I type in an URL in Alfred search bar, I can then use the default binding Shift/⌘ Y to toggle a preview of that URL in my default browser.

image.png

image.png

My take on a better dictionary

Now that QuickLook feature is awesome, and ideas quickly popped into my mind to use it to improve the definition look-up experience. The idea is simple, I can type in the word I want to look up for, and then hitting Shift will open the preview of the definition in any of the online dictionaries I have set. Let's take a quick look at the end result before moving on to the implementation.

  • en is the keyword and the word after that is whatever I want to look up for. Currently, I have two online dictionaries setup, Oxford and Cambridge

image.png

  • Now I can easily navigate to the dictionary I want to look up from and hit Shift to open the preview.

image.png

  • And that's it, I am pretty happy with this workflow. And here is what I did to get it to work. It is super simple, all I need to do is to create a blank workflow, add a Script Filter Input and the following script. This script is just an example for English-English definitions, you can also set it up for online thesaurus, English-to other language definitions, translations, etc.

image.png

require 'json'

dictionary_list = [
    {"Oxford Dictionary": "https://www.oxfordlearnersdictionaries.com/definition/english/{query}?q={query}"},
    {"Cambridge Dictionary": "https://dictionary.cambridge.org/dictionary/english/{query}"}
]

script_filter_items = []

dictionary_list.each do |hash|
    hash.each do |k, v|
        script_filter_items.push(title: k, quicklookurl: v)
    end
end

puts({ items: script_filter_items }.to_json)
Enter fullscreen mode Exit fullscreen mode

Caveat

Thank you for reading this far, if you decided to give it a try please be aware that:

  1. This flow will not work if you don't have an internet connection
  2. You might see advertisements in the preview depending on the online dictionary you are using.

Top comments (0)