Challenge: automating reassignment of keyboard keys

I write in Nisus Writer Pro, and grammar check using Grammarly. NWP is set to default to typing curly quotes, both single and double. Grammarly, for some reason, defaults to straight quotes and currently has no way to change that. Thus, if I edit in Grammarly and type a quote key, the document now has a mix of curly and straight quotes, which triggers a global error in Grammarly asking me to choose whether I want all curly or all straight quotes. Annoyingly, it jumps to the first instance of a quote mark to report the error! This happens over and over. I’ve complained to Grammarly and they are working on it. But meanwhile, I’d like a workaround.

One solution would be to use a Keyboard Maestro macro that would trigger when I activate Grammarly and re-assign my quote keys to default to typing curly quotes. Is there a way to re-assign keys in KM or in AppleScript (which I’d trigger in KM)?

Another thought, maybe simpler: Two macros, one to copy text to the clipboard and then change all quotes to straight (which I then paste into Grammarly). Then, have a macro that copys text from Grammarly, changes all quotes to curly, and then paste into NWP. I may wanbt to do the paste manually so I’m sure it goes in the correct document and location. Hm…I may be able to do this myself. But the automated reassignment of keys still interests me.

I just wrote two simple macros in Keyboard Maestro. They apply a filter to the system clipboard. One changes quotes to all dumb. The other to all smart. I trigger the “dumb quotes” filter when Grammarly activates, so that what I’ve copied from Nisus Writer Pro arrives in Grammarly with dumb quotes. Then, when I copy from G back to Nisus Writer Pro, activating the latter triggers “Smart Quotes,” and that’s when get pasted back into Nisus Writer Pro. Simple!

But I still would like to be able to reassign keys with a macro, if that’s possible.

On the surface, you could create two macro groups. Each set to enable only when particular apps (NWP / Grammarly) are activated. Within each you have macros that trigger on a typed string and then insert text by typing that substitutes the character you enter with the character you want to be entered in that app.

However, smart quotes are smart which gives you a problem. Opening smart quotes and closing smart quotes for a string curl in opposite directions. In some languages, they even locate in different places (top and bottom of lines for example). But the point here is fundamentally that Keyboard Maestro would not know which one to use as it does not know about previous entries.

Given that you might move the cursor and/or delete previous entries, Keyboard Maestro would have to constantly receive updates of what is going on in the editor, and not all smart quotes are quoting - there are curl apostrophes too.

This is why this sort of thing is best left to the editor for live editing. Your approach of transforming the text at transfer is probably the best time to do this. However, it still means taking into account all the points I’ve set out above. The difference is you are actually able to give Keyboard Maestro the text and let it process it properly with its built in clipboard filter for quote conversion.

For what its worth, when I’ve tried the smart/dumb quote filtering in Keyboard Maestro previously, and I couldn’t get it to transform the clipboard reliably. Having just tried it again now, it doesn’t seem to do anything at all when I pass in a string containing dumb or smart quotes via the system clipboard; I’m not sure what’s going on there. I use Keyboard Maestro for many things, but when it comes to quick text transformations, my go to tool is TextSoap. The smart/dumb quote transformation has always worked flawlessly for me, including on the content I just tried with Keyboard Maestro.

I ended up having Grammarly change all quotes to straight when it first flags inconsistent punctuation. When I copy back to Nisus, I run a Nisus macro I created to change all straight quotes to curly. That solves the problem. It would be lots easier if I could just type curly quotes in Grammarly, but it still only allows me to type straight quotes. If there are any curly quotes in the document, this creates an “inconsistent punctuation” situation. That should not be happening.

Several people suggest Pandoc for converting between RTF and Markdown. I tried it but could not get it to properly convert everything in my documents. I find the Ulysses Paste From and Copy From commands work best for me.

1 Like