Homonym or homophone for dictators, please?

Not being able to type well, I almost exclusively use native dictation on my Mac (I have Dragon Dictate but it’s unwieldy for everyday use). Naturally dictation is really lame at homonyms/homophones. Unfortunately, while the dictionary extension helpfully includes a thesaurus section, there’s no option for homonyms/homophones. There are such animals, such as https://homophone.com/

Us dictators would surely love such an extension!

1 Like

I just found your extension snippets option, which is ultra cool! So I made a little one but so far all it does is open that homophone website. Getting it to paste & search & present a word list will be more complicated; my programming experience is higher level (i.e. less sophisticated!), like FileMaker scripting…

# popclip
name: Homophones
url: https://homophone.com/search?type=&q=

If you’re willing to dabble with an API, you could try Datamuse API — it looks like there’s a “sounds like” parameter. If I have time I’ll try to put together a URL for a snippet and post it here.

That was a lot easier than I thought. The following URL, used in a snippet, will return a JSON object that you could then do something with.


For example, https://api.datamuse.com/words?rel_hom=too returns:


That’s a cool find. So the result is a delimited list out of which one would need to extract only the found words and then present those as a list of options to replace the selected text. I could do this in a filemaker script or similar, but I don’t even know what language we’re talking here.

It’s really annoying that Apple’s dictation already lets you do this but only on some devices or in some applications. Shouldn’t have to reinvent the wheel…

The results are in JSON format. I’m pretty sure PopClip will let you use javascript in a snippet. I don’t think I have time now, but I will try to cobble something together

:+1: The axios example will be a good starting point.

1 Like

@nick — I’ve tried writing a snippet for this. I have a script that works in Scriptable (since I messed around with it on my phone), but I’m having trouble getting it to work as a PopClip snippet.

In trying to troubleshoot, I discovered I can’t even get the example “JS network example” snippet to work. I add the following (copied from GitHub) using the PopClip snippet functionality:

# popclip JS network example
name: Download Text
icon: symbol:square.and.arrow.down.fill
requirements: [url]
entitlements: [network]
javascript: |
  const axios = require('axios')
  const response = await axios.get(popclip.input.data.urls[0]) // throws for non-2xx status
  return response.data
after: copy-result

Then I highlight this URL: https://api.datamuse.com/words?rel_hom=too — and I get the shaky-x, indicating that it didn’t work.

I tried installing axios on my machine, but it didn’t work (unsurprisingly — I assume you’d included axios with PopClip).

Any suggestions? FWIW, I’m running macOS 10.15.7 and PopClip 2021.11

Great stuff. So what is happening here is that the API is returning JSON data type and the axios library has converted the response to a JavaScript object (response.data's type varies according to the response mimetype). So response.data is an object not a string.

You could put something like return JSON.stringify(response.data) to force it to a string for testing purposes (that works, I just tested it)

BTW if you turn on and view debug output it helps a lot. Best to filter it to the Extension category of the PopClip process. Also you can use print() to output variables to the debug-- that’s how I figured this out.

P.s. if you are doing any complex JS coding you might want to package this up as a regular externsion with a separate .js file. You could then use a JavaScript-aware editor like VS Code (which I use) which will do syntax checks for you and generally make life a bit nicer. However you can of course do it as a snippet if you wish! (Let me know if you would be interested in a post about how I set up my editor to make JS extensions…)

1 Like

I’d love a post like that!

1 Like