This is an interesting challenge. I have some software that I use that requires it to be run in browser extension. I need to spell check some regions on the page. I can run JavaScript against it, but I cannot use a spellchecker extension because, well, it's an extension itself.
I was wondering whether I could selectively copy parts of the page to the clipboard, then run a spell checker (spell seemed like it may work) and output the results of any identified misspelled words in a window.
But it's not really what I want - ideally those words should be highlighted in the context of the page.
I don't imagine there is an easy way around this, but if anyone has any bright ideas about how to trigger some kind of in-page spell checker in Chrome (in an extension), I am all ears!
I am bombarded with ads for spell checkers for Chrome whenever I try to watch a video on Youtube. Don't you see the same ads? Don't they do exactly what you are asking for?
If your Mac is an M1 Mac, you may have another option when Monterey is available. Monterey has high speed OCR abilities on M1 Macs, and it would be very easy for someone to write a KM macro that checks your screen for spelling errors.
I am bombarded with ads for spell checkers for Chrome whenever I try to watch a video on Youtube. Don't you see the same ads? Don't they do exactly what you are asking for?
The key thing here, which I noted in the original post, is that I am trying to check web content that is in a window of an extension; it's not a standard browser window. So, yes, I do have a grammar/spell checker to hand. I use Grammarly, generally, and this would be perfect in most cases, but I cannot run an extension on another extension's content.
Hence trying to work out a way that KM can analyse the pertinent sections of the page (basically some form fields) and to check for spelling/grammar. Ideally inline and in context, but I would be happy if I could get it to spit out any typos in a separate window for me to track down in the relevant field.
Ahh. I am a failure for failing to understand. Sorry. Well, I did point out that if you have an M1 Mac you can use OCR to read text in any window, including extensions, starting with Monterey. Basically you would use KM to screen capture the area of the browser that contains the extension, then OCR that window, then perform a spell check on the text read in the window. Would it be exactly what you want? No, but it would be fairly close. I don't use Chrome because it damages the performance of my Mac pretty badly, so I can't really write the code for you. Basically you just use KM to calculate the window location, capture that part of the screen as an image, perform OCR on it (it's VERY fast in Monterey on an M1 Mac) then run the words against a dictionary, then perhaps speak or display in a window the misspelled words.
Come to think of it, I think Apple announced that the OCR feature would also work on Intel Macs. I forgot about that.
I may not even need OCR - I could trigger keystrokes CMD+A, CMD+C to copy the whole page and do it that way. Still not quite what I want (inline checking) but doable. That said, I didn't have much luck getting spell (which was recommended elsewhere on the forum) as a solution. I downloaded aspell (via HomeBrew) and can run it in the Terminal, but can't seem to to get it to work inside KM. I was referencing this list - Check the Spelling of Text on the Clipboard - #2 by ccstone where @ccstone suggested it could be done using a simple shell script of aspell list | sort.
Thanks, I had already set up a variable for this (attached), but it is not working and I'll confess I don't know enough about shell/terminal type stuff to know how to debug.
What could/should I do to reveal the issue? My assumption is that I need another value in there that relates to how I have spell installed. How could I get that value?
So, I was asking a friend who is a Linux guru and very comfortable with all things script related I wanted to work out how I could trigger the spell check in such a way that it would show me issue in context rather than just a list. He created the following which I am sharing because, well, I hope it's useful to other people
#!/usr/bin/env python3
import sys, subprocess
HIGHLIGHT_BEFORE = "👉"
HIGHLIGHT_AFTER = "👈" # if you just want a highlight before, make this ""
cmd = ["aspell", "pipe"]
# add any extra options given to our command to the aspell command
if len(sys.argv) > 2:
cmd += sys.argv[1:]
for line in sys.stdin.readlines():
# feed the line to aspell; will throw obvious error on failure
proc = subprocess.run(cmd, input=line, text=True, capture_output=True)
corrections = []
for oline in proc.stdout.split("\n"):
if not oline.startswith("&"): continue
parts = oline.split()
from_start = int(parts[3][:-1]) # will be 28: so strip off colon
corrections.append((from_start, from_start + len(parts[1])))
if not corrections: continue
# Once we've got all the corrections, handle them in reverse order
# so that the indices for later ones aren't affected by earlier
new_line = line[:].strip()
for start, end in sorted(corrections, key=lambda n:n[0], reverse=True):
new_line = new_line[:end] + HIGHLIGHT_AFTER + new_line[end:]
new_line = new_line[:start] + HIGHLIGHT_BEFORE + new_line[start:]
print(new_line)
There is only one thing I would still like this to do - ignore words that I have added to a dictionary. I have this working:
aspell list --personal=spell-check-ignore-list.txt --home-dir=/Users/lloydi/path/to/Dictionaries | sort -u
Where the file spell-check-ignore-list.txt includes all my words to be ignored (one per line) and has:
personal_ws-1.1 en 0
As the first line.
What I cannot work out is how I change the bigger, in-context script up top to also reference and ignore my dictionary/ignore list.
Is anyone able to show how that script could be adapted so that it works there too, please?