Google Spell Check

I have a Alfred script that takes the selected text and runs a bin/bash script to run it through google spell check:

I am looking to do something like this in KBM but can't seem to figure it out, here is what I got:

It does not run the script at all, what am I missing?


Update, my goal is to copy the result of the script (word with correct spelling) to my clipboard (or set as variable).

I don’t believe you need the “With input from” part, but your KM variable does not appear to be defined properly for a shell script. It needs to be like so:


…and some things require it to be enclosed in straight double quotes.

See this wiki entry for more info.

1 Like

Hi @gianthobbit. Check out: Execute a Shell Script

Here's an example action:

If you need help with your macro, I suggest uploading it. Instructions here: Post/Upload Your Macro—KM Forum

And even if you don't need help, it would be nice to share it here. :grinning:

1 Like

Thanks everyone, it still does not appear to be working even with the correct syntax for variables.

Better aText.kmmacros (2.4 KB)

The workflow here is:

  • Select text
  • Copy it
  • Spell check it with google
  • add it back to the clipboard


Hi @gianthobbit. Issues like this are often related to the PATH. Here's an example macro that shows you some possible solutions:

DOWNLOAD Macro File:
Three Methods to Run a Python Program from a Shell Script.kmmacros (18 KB)
Note: This macro was uploaded in a DISABLED state. It must be ENABLED before it can be run. If it does not trigger, the macro group might also need to be ENABLED.


BTW, the Python tool sounds interesting. When you're done, I'm sure others, like myself, might find it useful.

Sorry, that is beyond my understanding.

The incorrect word should be copied to the clipboard, I'm defining the variable and then passing it into the script which should return the corrected word to the clipboard. This functions right now in Alfred.

Not sure where the path comes into play into this.

I guess I could just run the alfred workflow from KBM - I figured this would be super simple, it's a very basic script...

Hi @gianthobbit. If you supply the script, I'd be glad to create the macro.

The script can be placed between three backticks.

Here's an example:

print('Hello, world!')

You rock, thanks! I thought you could pull that from my KBM macro export, sorry should have put that here as well.

python {"$KMVAR_VarName"}

I have it set to return the request to the clipboard.


Sorry, I meant the actual Python code, the file:

That's a file somewhere on your Mac. Maybe it was installed by Alfred, or maybe an Alfred plug-in.

Ahhh! I thought this was a request to run this script online, did not realize it was local. I was able to track it down, thanks!

import urllib2
from urllib import urlencode
import json

url = "{query}"

hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11'}
query = """"""

keys = [


pl_cse = '009341357436794688484:bi6ngbl4mvk'
en_cse = '009341357436794688484:rvhujssywbq'

def correct(word):
    result = word
    for key in keys:
            full_query = query + (
                urlencode({'key': key, 'cx': pl_cse, 'q': word})

            search_result = json.loads(
            if 'spelling' in search_result:
                return search_result['spelling']['correctedQuery']
                return result
        except urllib2.HTTPError:
        return result + '.no_key'

if __name__ == "__main__":
    import sys
    import subprocess
    c = correct(" ".join(sys.argv[1:])).strip().encode('utf-8')
    sys.stdout.write(c)"""echo "{0}" | tr -d '\n' | pbcopy""".format(c), shell=True)

Is this what you needed?

@gianthobbit, it is, but...

The code includes an API key. Generally, keys like this are not shared amongst users, rather sites invite users to apply for their own API keys.

If you direct me to the original source of this code, I may be able to sort it out. You mentioned Alfred—I'm assuming it was a Shared Workflow, but with a quick search I was unable to locate it.


Funny enough I can't track down anything either, all links have been taken down.

So your saying I'm using someone's personal API key to make this work?

Is there another method I could do spell check? I liked this one because Google Spelling is pretty bullet proof.

Yes, likely. Maybe that's why it was removed. Is the Alfred version you have still working as expected?

There are several ways this could be done using KM. If I'm not mistaken, I think there's an active thread on that very topic.

Also, you might want to check out this macro: Browser-free web search

Take a look at Literary Toolbox III and Text Toolbox I. Literary Toolbox has a very simple macro that lets you check spelling on a selection using the macOS built-in Dictionary application, which can check anything from single words (providing likely alternatives) to whole files. It can also get you to a Thesaurus entry with a single click. A very handy if rarely mentioned utility.

[Edit: link fixed]


Just recently I built a macro using Aspell (a Homebrew package) to spell check. Here’s a link to it in case you want to check it out.

1 Like

Thanks. Sorry about that. I fixed the link in case anyone else stumbles on it.

Meanwhile, here's the simple macro from the suite:

Dictionary Macro

00)Dictionary.kmmacros (7.2 KB)

I had considered using aspell for single word checks like @cdthomer's macro (and which Spell Catcher used to do for me) but when I realized Dictionary could do that, I thought it more efficient to use the default macOS solution rather than explain homebrew and aspell installations. Which, however, he's done very nicely.


Thanks everyone!

Do you think aSpell is superior the mac built in dictionary @cdthomer? That is why I was using the Google Spell check script, I can be terrible at spelling sometimes and if I select a sentence and activate it - it would almost always get the word even if I butchered it (it got the context form full sentence).