Word 2011: Fix ‘Copy’ command with Keyboard Maestro

Posted by Pierre Igot in: Microsoft, Pages
January 5th, 2013 • 3:14 pm

There are two things in Word 2011 (admittedly, among numerous other ones) that are a constant source of irritation for me and that are so basic that it’s quite clear that Microsoft’s engineers have absolutely no clue about how people use their software in the real world, so much so that there is no hope of them ever fixing such problems.

Consider the following situation:

word2011-selectedwordinbullet

All I’ve done is that I’ve double-clicked on the first word in this paragraph to select it. And already the first problem appears: Word has included in the word selection the trailing space after the word. This is simply wrong. A double-click on a word means that you want to select that word, and that word only. There is no reason for the user to want to select the trailing space as well. Maybe once upon a time, this was useful because word processors were not smart enough to automatically delete the extra space if the user opted to delete the selected word. But today’s word processors, like Pages ’09 and indeed Word 2011 itself (!), are smart enough to delete superfluous spaces automatically, and so the automatic selection of the trailing space makes no sense whatsoever.

This trailing space is problematic because I often have to copy words (or phrases) and paste them into a search engine or another similar tool, and that tool is not necessarily “smart” enough to know that it is supposed to ignore the trailing space.

Yes, with smart clipboard features, most of the time Word automatically removes the extra space when the word copied to the clipboard with the trailing space gets pasted elsewhere (most of the time, but not always, depending on the presence of things like non-breaking spaces, which are not standard spaces, and are used quite often in French typography, for example). But what if you switch to another application with the copied word (and trailing space) in the clipboard? That other application won’t necessarily be smart enough to know that this trailing space is supposed to be ignored. And since Word is the only OS X application with this non-standard behaviour, inevitably there are problems with this extra space in other applications. But clearly Microsoft has no intention of ever fixing this issue.

The other problem only transpires once I copy the selection in the picture above, and then switch to another application and paste it. In other applications, the result is this:

word2011-selectedwordinbulletpasted

As you can see from the position of the insertion point, and as predicted above, OS X has pasted the copied word with the trailing space, even though it’s completely undesirable in this context (the Spotlight search tool in LaunchBar, but it’s just one example among many).

But even worse, OS X has also pasted a bullet and a tab character before the copied word! This is completely idiotic. It makes absolutely no sense to treat the automatic bullet formatting, which applies to the entire paragraph, as if it applied to the first word of the paragraph that was selected and copied by itself. And Word’s engineers clearly know this, because if you copy the selected word above and paste it in another Word document, Word does not include the bullet formatting with it. It’s only when you paste the contents of the clipboard in another application that, for some reason, Word includes the bullet formatting along with the word, in the form of this bullet + tab combination.

This is quite clearly because, when you copy something in Word, even a single word by itself, Word 2011’s handling of the clipboard mechanism is such that multiple versions of the selection are included in the clipboard, included a “plain text” version that includes the bullet and the tab, which never gets used by Word itself, but which somehow someone at Microsoft believes is useful to have when pasting the contents of the clipboard in another application that will only accept the plain-text alternative.

It drives me nuts, because, again, I encounter the problem (along with the trailing space) whenever I copy a word that’s at the beginning of a formatted paragraph and paste it in another application, like a search tool or a database tool. And the problem does not just affect the automatic bullet formatting. It also affects the first word of paragraphs of text formatted with automatic numbering. When copying such a word in Word, the plain-text alternative includes the plain-text version of the automatic number (i.e. the actual alphanumeric characters, along with the punctuation) as well as the tab character — and again, the extra characters are pasted along with the word in other applications. And it also affects any selection that includes the first word, so I also get the extra stuff if I select and copy, say, the first five words of the paragraph.

I constantly find myself having to delete this extra cruft that Word automatically adds to the plain-text alternative in the clipboard before I can submit my search request in the other applications that I use. Or I submit the search request before I notice the problem and of course, the search results are completely irrelevant, because my search tool or database does not know how to handle a search string that includes a bullet or a number before the key word(s)!

Today, I decided I was really tired of this, and so I came up with this simple Keyboard Maestro macro:

km-word2011copy

It highjacks Word 2011’s own “Copy” command and instead, does the following:

  1. It tests the clipboard’s contents to see if it contains the bullet + character sequence. (Fortunately, KM applies this test to the plain-text alternative, so it finds it there.)
  2. If so, it runs a small BBEdit text factory that remove it.
  3. And then it applies the “Trim Whitespace” clipboard filter that’s included in Keyboard Maestro, which removes the trailing space at the end.

It is, at this point, a far-from-ideal solution. First of all, the best test I can come up with in KM is a test to find the bullet + tab sequence anywhere in the clipboard. As far as I can tell, there is no way in KM to test to see if this sequence appears at the beginning of the clipboard only, and also to test whether the clipboard contains entire paragraphs of text, where removing the bullets might not be the preferred scenario.

Then, it fails to test for the presence of an automatic number converted into plain text, followed by a tab. This, again, would require a much more refined test than what KM’s own control flow features allow. Fortunately, the bullet is the most common manifestation of this problem that I encounter, so the macro still helps in the majority of cases. But ideally I’d like to have a macro that tests for the presence of any automatic list formatting converted into plain text by Word behind the scenes in the plain-text alternative of the clipboard’s contents.

As well, the BBEdit text factory I designed is a simple search/replace function that replaces all occurrrences of the bullet + tab combination anywhere in the clipboard with nothing. Ideally, I’d just want to replace the first occurrence with nothing, or trim the first two characters of the clipboard, but BBEdit’s options are too limited to enable me to do this. (It should also be noted that I could ditch the test altogether and apply the replace-all operation in all cases, but I am still hoping to have a more effective detection test some day and be able to apply the transformation only if the bullet + tab appears at the very beginning of the string of copied text.)

Finally, the “Trim Whitespace” clipboard filter is probably too agressive and removes whitespace that I might not want to remove in some situations.

I suspect that, if I took the time, I might be able to come up with AppleScript-based solutions for some or all of these issues with my macro. But I am afraid I just don’t have the time to explore things further at this point. So this macro will have to do, with its own flaws and limitations. I’d much rather have a macro that works properly for the most common scenario and only requires further adjustements in less common ones, than have to continue to live with a situation where Word forces me to make manual adjustments each and every time I encounter the most common scenario.

If you too are constantly frustrated by Microsoft Word’s multiple annoyances and flaws, I urge you to explore the use of a third-party tool such as Keyboard Maestro to remedy or at least alleviate the most common issues you have with the software. (Don’t waste your time trying to fix Word using its own customization features. You’ll ultimately be punished for it, because the carelessness of Microsoft’s developers extends to these customization features as well, and there is also absolutely no guarantee that your fixes will remain supported. Remember what happened with VBA in Word 2008.)


One Response to “Word 2011: Fix ‘Copy’ command with Keyboard Maestro”

  1. Betalogue » OS X Tip: Better than ‘Paste and Match Style’ says:

    […] If, however, you try and paste this particular Clipboard into another application as plain text (for example, in BBEdit, or in a search field on a web page), then the bullet or automatic number will be included in its plain text form (i.e. as actual bullet or number characters, plus whatever separates them from the following text) at the beginning of the pasted text. This is extremely irritating, and I have talked about it before. […]