Bug? Filter Clipboard → Smart Quotes doesn’t seem to be smartening apostrophes

Is it just me or does Filter Clipboard → Smart Quotes not seem to be smartening apostrophes?

More specifically, I created a macro that takes the currently selected text and runs Filter Clipboard → Smart Quotes on it, but it doesn’t seem to be smartening the apostrophes within the selected text (?).

If it may be of interest, here’s a test passage that you can try it with:

I wasn't a particular fan of the music in the '80s, but then "Take on Me" came on the radio and all was right with the world. And then she blurted, "I thought you said, 'I don't really like '80s music'?"

When you run the macro on that text, you get:

I wasn't a particular fan of the music in the '80s, but then “Take on Me” came on the radio and all was right with the world. And then she blurted, “I thought you said, 'I don't really like '80s music'?”

The result that I’d expect is:

I wasn’t a particular fan of the music in the ’80s, but then “Take on Me” came on the radio and all was right with the world. And then she blurted, “I thought you said, ‘I don’t really like ’80s music’?”

If it might help at all, here’s also a downloadable version of the macro: Smarten text with Cmd-8.kmmacros (2.5 KB)

(To use the macro: Type some text in an editable field, then select the text and press Cmd+8 to smarten it.)

— Ashley

No, it’s not just you. It seems it is completely ignoring apostrophes and single quotes.

I just tried the “smartening” feature of a couple of different apps (BBEdit, Word, Nisus, the OS’ smart quotes): they try to convert single quotes and apostrophes, but they all get it wrong:

The second part of the last sentence is indeed tricky.


However, I got a correct result from the Pandoc converter:

To convert with Pandoc run this in the Terminal (or in a Shell Script KM action):

pbpaste | pandoc -t plain --smart | pbcopy

It converts the clipboard content and pastes it back to the clipboard. (You have to install Pandoc, for example via Homebrew.)


PS/Edit:

Add the --wrap=preserve switch to the Pandoc command, to prevent it from hard-wrapping the lines:

pbpaste | pandoc -t plain --smart --wrap=preserve | pbcopy
1 Like

It does not attempt to handle single quotes at all, specifically because they can be used as apostrophes which makes figuring out which direction they should go very difficult.

For example, what if it is:

'80 people like '80s music'?

Without impossible smarts, there is no way to know which one the first two is an opening single quote and which is an apostrophe.

So you’re on your own for that, perhaps someone can attempt a clever regular expression.

I’d like to think that the perfect needn’t be the enemy of the good.

At the moment, Keyboard Maestro can’t handle apostrophe smartening, and even if there might be a lone edge case that could throw off its smart-apostrophe handling, I think that an earnest attempt at apostrophe smartening would nonetheless be an improvement over no apostrophe handling.

@peternlewis, as an RegEx pro yourself, surely you knew that was easy:
Search: '(.+[^ \t]+)'
Get: Capture Group 1

See regex101: build, test, and debug regex

Sure, but that matches the whole string for the case I mentioned and also for this one:

'80s music is 'liked by 80 people'?

I don't see how the search can differentiate the quoting in that from:

'80 people like '80s music'?

without knowing that "80s" is an abbreviation and "liked" is not.

It is a valid comment, but as a general rule I prefer "always correct" or "doesn't exist" over "works most of the time" if for no other reason than its easier to handle support that way.

"works most of the time" can be very problematic when it fails, for example you start trusting it and then send out your incorrectly formatted text to a million people in your mailout (which, admittedly would not really be a problem given I rarely receive a government mailout that doesn't have a typo in the first paragraph, but I would find it embarrassing if I was responsible for it).

There are, of course, cases in Keyboard Maestro that violate this rule, but the return has to be worth it, and the workaround without the feature has to be very difficult. In this case, if there is a good RegEx that works enough of the time for you, then doing it with a Search & Replace is doable.

Honestly, I think this is really an extreme case, and any algorithm (see Pandoc) that can handle the OP’s sample text should be fine for 99.8% of the time.

As said, programs like MS Word and others are doing it worse, and they are doing it nevertheless…

@handcoding, if you are going to use Pandoc you may want to add a --wrap=preserve to prevent it from adding line breaks. I have edited my post above.

3 Likes