I’m looking to create a script that automatically logs in a .txt file the words I look up in Apple’s native dictionary app. In a word, when I use the dictionary app to look up a word, I’d like to have that word recorded. I want to be able to review the words I had to look up, in order to become more familiar with them and improve my vocabulary.
Ideally (though certainly not necessary) this log works with the native force-click and right-click → look up functionality. It could also check if a word has been looked up before, and not add it to the log if so.
I know that some form of this used to be possible, because there are a few scripts online still. But I’ve tried them all and they seem to be defunct at this point. I would amend them to try to salvage them, but that’s beyond my skillset. I also cannot find an applescript dictionary for the dictionary app.
Any help would be greatly appreciated! If another way of achieving this is known, that’s fine too! Open to any and all suggestions. Thanks guys!!
@dictionary. The macOS Dictionary app is not scriptable, which complicates matters a bit. The following script prompts for the word to define and then opens and shows that word in the Dictionary app. The word is then saved to a text file in your Documents folder. This script worked without issue on my Sonoma computer.
To define a word selected in another app, a Shortcut solution is best, but you have to be on a recent version of macOS.
set theFile to (path to documents folder as text) & "Dictionary Words.txt" --set to desired value
set theWord to text returned of (display dialog "Enter a word to define" default answer "" with title "Dictionary")
if theWord is "" then error number -128
open location "dict:///" & theWord --from Nigel
try
set existingWords to words of (read file theFile)
on error
do shell script "echo \"\"" & theWord & " >> " & quoted form of (POSIX path of theFile)
set existingWords to {theWord}
end try
if existingWords does not contain theWord then do shell script "echo " & theWord & " >> " & quoted form of (POSIX path of theFile)
There is a Look Up in Dictionary service. I have it configured to opt-f8.
With it, I can select a word in any app (apparently) that interacts with services and by typing opt-f8, launch the Dictionary app with that word entered and highlighted. It would likely be straightforward to script something similar that triggered the service and copied the highlighted word to the clipboard. From there, it could be logged however desired.
This shortcut looks up the selected word in the Dictionary app and saves the selected word to a text file in the folder set by the user in the File action. The shortcut can be run by way of the Services menu, or a keyboard shortcut can be set in the actual shortcut (see screenshot below).
This enters a word into the currently selected dictionary in Dictionary.app. I don’t know of a way to adapt the URL to specify a particular dictionary. This would probably have to be done with a keystroke.
set theWord to "peavine"
open location "dict:///" & theWord
I’m not clear if @dictionary actually wants to include the look-up process or simply to save the word currently entered. And is the word’s meaning required in the text file too?
@peavine 's shortcut solution from post #4 works well as a working simple version (thank you!). (I’m on Sonoma 14.4) This solution is a significant improvement over your initial script, since it does not require I enter a word–the logging and defining are consequences of a basic keyboard shortcut, which is more much efficient and feels more natural. (I was also wondering if the shortcut can be configured such that I can trigger it by a keyboard shortcut strong textHowever, there is still more functionality desired.
@Nigel_Garvey I do not need the definition itself to be written in the text file. But to your point, there are many instances in which I would not want to pursue the whole look-up process (dictionary app popping up), but may simply want to record the word. This is especially true where I’ve used force-click or right click → look up, have the definition in front of me, and simply want to log the word. Perhaps a second script/shortcut should be configured for this? It seems as though the only shortcut dictionary.app action is “Show definition of” and what we’d need here is a “Getdefinition of.” Not sure how to approach this, then.
@dictionary. The shortcut can be triggered by way of a keyboard shortcut with the Add Keyboard Shortcut option (see screenshot below). I tested this and it worked fine.
The following shortcut is similar to that above except that words are listed in the dictionary log only once.