Really Smart Paste: Keyboard Maestro and BBEdit to fix copied text from on-line database and other sources

Posted by Pierre Igot in: Macintosh, Microsoft, Pages
November 28th, 2012 • 11:02 am

As a professional translator in Canada, I am constantly referring to the TERMIUM database, which became accessible free-of-charge a couple of years ago as part of the Language Portal of Canada.

One thing I do not like when using on-line databases, however, is having to retype things. Whenever I have to look up a term, I tend to copy it from the source and then paste it in the search field in the database. Conversely, whenever I find a term in the database, I tend to select it in the on-line interface and copy it so that I can switch back to my word-processing application and paste it there.

This process raises several issues: text copied from an on-line database interface is, by default, in rich text format (with font face, character size, colour, etc.); it can be surrounded by undesirable white space that is copied along with it; and whenever the text contains apostrophes, which is quite common in my target language (French), these apostrophes tend to be straight and not curly.

All these things can be fixed manually after pasting the copied term in the target application, but it is of course rather painful to have to fix them each and every time or even to have to remember to do batch replacements later on. Which is why I have, over time, developed tools to help me automate this process.

Over the years, I have struggled with the idiosyncrasies of the target applications that I use (mostly Pages ’09 and Word 2011, but also Adobe InDesign, TextEdit, etc.). But now I believe I have come up with a solution that is pretty good and definitely increases my productivity, so I thought I’d share it here:

pastefromtermium

Unfortunately, as you can see, it involves the use of third-party tools, namely Keyboard Maestro and BBEdit. However, that’s what productivity enhancements usually are: they require an initial investment, but they pay off over time. (I have been a user of both third-party tools for a long time, so the enhancement required no new investment for me.)

I chose the shift-command-V trigger because it’s easy to press, on my keyboard, with only the left hand, so that the right hand remains free to control the mouse, which tends to be necessary when dealing with on-line database interfaces. (They don’t have handy keyboard shortcuts for selecting search results.) I know this particular shortcut is used for other purposes in some applications, but these other purposes are far less important to me, so I’d rather use it for this. KM supersedes built-in application shortcuts, so it’s not even necessary to customize the application itself.

The first action in the Keyboard Maestro macro is a filter that trims the whitespace before and after the copied text. In my case, it enables me to work around a bug introduced by the revamped TERMIUM interface in Safari, which is that, when double-clicking on the very first search result to select it on the web, Safari also selects some invisible markup that ends up being converted into an extra carriage return before the text. (It’s hard to imaging anyone at either Apple or TERMIUM actually caring about this bug, so a fix will probably never happen.) The KM filter removes not only superfluous space characters, but also extra carriage returns. (For some reason, it also strips the formatting at the same time and converts the clipboard to plain text. But there is also a separate filter that does only that, which would be redundant here.)

The second action consists of applying a BBEdit Text Factory to convert straight quotes to smart quotes. KM has its own built-in filter for this, but it’s not as… smart as the one in BBEdit and can curl apostrophes the wrong way in some cases. The BBEdit Text Factory works very well.

Finally, the third action simply pastes the contents of the Clipboard, which has now been stripped of its formatting and the undesirable whitespace and also has had its straight apostrophes converted to curly apostrophes.

One additional benefit of this macro is that, for some reason, it also prevents the word processor’s pasting command from trying to outsmart the user by adding undesirable white space when inserting the text. This is particularly important in French, because there are many cases when I want to paste the term after a contracted l’ or d’ and I definitely do not want a space between the contracted article or preposition and the pasted text, which tends to happen otherwise. (I know that Smart Paste can be turned off altogether in Word 2011, but not in Pages ’09. And besides, Smart Paste is actually useful in other contexts. It’s just not smart enough to deal with all situations, and it’s definitely too English-centric.)

I should also note that, once this macro has been used once, the text in the clipboard remains in its stripped form, so it can be pasted again and again using simply command-V.

Finally, this macro is useful not just for pasting from TERMIUM, but also for fixing copied text from a variety of other sources. And it works the same in many different applications, including Pages ’09, Word 2011, InDesign CS6, etc.

It’s a bit sad that, after all these years, we still have to effectively “hack” our systems to make them behave properly as writing tools, but writing is only one of the many uses of a computer, and companies like Apple and even Microsoft tend to focus far too much on other uses. There is a definite lack of innovation in computing for writers, so our only option is to rely on third-party tools to enhance our productivity. Fortunately, these tools exist, and they work pretty well once you’ve learned how to use them.


Comments are closed.