App for macOS to add words to personal vocabulary list?

I search for a way to add unknown words in a personal dictionary or vocabulary list only by right-clicking the word and choosing the add option (in macOS). It would be very helpful for me to add the words directly to a vocabulary list, without breaking my workflow. I already found an addon for chrome which resolves my problem (you can see it on the attached screenshot). But I need a similar (overarching) solution that works with various apps (like PDF reader (Preview in macOS), other web browsers (safari)..). If there isn't any app for this "issue", would it be difficult for somebody without specific Swift (or macOS development) knowledge but expertise in other languages to write a small (background) APP in swift for helping me out?enter image description here


You can create an Automator Quick Action that takes the selected word as input and saves it to a predefined document. The Quick Action can then be configured with a keyboard shortcut of your choosing.

Setting it up

  1. Launch Automator (located in /Applications).

  2. Create a new document of type "Quick Action": enter image description here

  3. Search for "shell" and drag the "Run Shell Script" action to the right panel: enter image description here

  4. Configure it to receive selected text from the current application and add this script, modifying ~/Documents/Vocabulary.txt to your needs (see below for a fancier script):

    if [ "$@" != "" ]; then
        echo "$@" >> ~/Documents/Vocabulary.txt
    fi
    

    enter image description here

  5. Save the Quick Action with a meaningful name like Save to Vocabulary List: enter image description here

  6. Open System Preferences>Keyboard>Shortcuts, select Services from the list on the left panel, enable the Quick Action and set a "complex" keyboard shortcut, for example ControlShiftCommandV, to reduce the change of a conflict with an existing one: enter image description here

  7. Open an app, select some text, press ControlShiftCommandV and the text will be added to the file configured in the Quick Action (~/Documents/Vocabulary.txt).

Going fancy

You can easily extend the script's functionality (basic scripting knowledge required). For example, to add a timestamp and a link to the Dictionary app, use this script instead (note that the vocabulary list is now saved to the HTML file ~/Documents/Vocabulary.html):

if [ "$@" != "" ]; then
    timestamp="$(date +%Y-%m-%d' '%H:%M:%S)"
    dictlink="dict://$(echo $@ | sed 's/ /%20/')"
    ahref="<A HREF=\"$dictlink\">$@</A>"

    echo "$timestamp - $ahref</br>" >> ~/Documents/Vocabulary.html
fi

When opened in Safari, the vocabulary file looks like this:

enter image description here

and you can click the word to look it up in the Dictionary app.