January 28th, 2008 • 5:24 pm
If this blog post’s title sounds very similar to a previous Betalogue post title, it’s because it is. Back in 2004, I wrote a tip about creating a direct command for pasting unformatted text in Word 2004.
Thanks to the infinite generosity of Microsoft’s MacBU developers, we have to start all over again in Word 2008, because of the elimination of the Visual Basic for Applications macro scripting feature.
I am, in fact, very ambivalent about putting any further effort into customizing Word 2008. I am not a masochist. Who’s to say that Microsoft won’t break AppleScript support in the next version of Word for Mac OS X? What guarantee do we have that it’s worth reinvesting more time and effort into fixing Microsoft’s Mac software? Certainly, the history of my relationship with Microsoft software suggests that I should do as little as possible to make life tolerable—and use Apple’s Pages whenever I can.
Which is exactly what I plan to do. So I will only post tips for customizations that I find absolutely essential. One of those is direct access to a “Paste without Formatting” command. Apple’s Pages provides direct access to such a command, which is called “Paste and Match Style.” It’s in the “ ” menu and it uses the command-option-shift-V shortcut, which is what I am used to.
If you want to paste unformatted text in Word 2008, on the other hand, you are forced to go through a multiple-step process. You can either used the “Match the Destination Formatting.”” command in the “ ” menu and then choose the “Unformatted Text” option or use the regular “ ” command (which pastes with formatting) and then click on that stupid toolbar button that appears floating in mid-air next to the pasted text and choose the option to “
Neither approach is acceptable for a task that I tend to repeat many, many times throughout the day.
So the other day I decided to try and figure out if there was a way to achieve this via AppleScript. I explored the flavour of AppleScript that Microsoft uses in Word, and found it very unpalatable—but it’s not like we have much choice, do we?
By the way, if you follow the link above, you’ll find that most of the documentation refers to AppleScript support in Office 2004. As far as I can tell, nothing much has changed between Office 2004 and Office 2008 in terms of AppleScript support. Microsoft did not even bother to provide us with recordable applications, which means that we are all forced to become developers and learn how to write scripts manually. Thanks, Microsoft.
Anyway, after much trial and error, here’s the script that I ended up using for this particular command:
tell application "/Applications/Microsoft Office 2008/Microsoft Word.app"
paste and format (text object of selection) type format plain text
I put a direct reference to the Word 2008 application rather than the more generic “Microsoft Word,” because I have kept a copy of Word 2004 on my system. Apparently, Microsoft recommends against running Word 2004 and Word 2008 in the same user environment and instead suggests to only run Word 2004 in a separate user environment and to switch back and forth with fast user switching. Fat chance of that happening on my machine. I’d rather live dangerously than waste my time trying to conform to Microsoft’s definition of a productive workflow. So I have Word 2004 and Word 2008 side by side and I’ll switch between the two if I want to, because, you know, Word 2008 is crap. Word 2004 is also crap, but a different kind of crap. Unfortunately, thanks to Microsoft’s infinitely helpful engineers, we now need both kinds of crap.
So does this little script actually work? Yes, if you don’t mind the totally illegible syntax. For a while I couldn’t get it to paste without replacing the entire contents of my document, but I then discovered that I was “telling” the wrong object. So now apparently this script tells the correct object and all is well—except that, after pasting, the insertion point is at the beginning of the newly pasted text rather than at the end. There is probably a complicated way to compute the length of the pasted text and move the insertion point manually to the other end, but I value my time. I’ll live with the insertion point at the beginning if I have to.
Now, how do you access this script in Word 2008? According to Microsoft’s own “Known issues in Office 2008,” it should be tricky:
Running Automator workflows and AppleScripts from the Office script menu is not currently supported under Mac OS X v10.5 (Leopard).
But I’ve found that, if I put the script in the “Word Script Menu Items” folder inside the “Microsoft User Data” folder, it does actually show up in the script menu in Word, and the command works. So who knows what they mean with this “known issue”? They can’t even get it right when things actually work as expected.
Better still, I was actually able to assign a shortcut to this command using Mac OS X’s built-in keyboard shortcuts feature in System Preferences. While the script menu is part of the Word 2008 menu bar, Word 2008 itself doesn’t actually let you assign keyboard shortcuts to the scripts in that menu. The “Customize Keyboard…” command does not mention scripts at all. So much for enhanced AppleScript support in Office 2008.
But since the script menu is, for most intents and purposes, a regular Word 2008 menu, apparently Mac OS X’s built-in keyboard shortcuts feature can be used to customize it. Phew.
I used the same command-option-shift-V shortcut as in Pages, even though Word 2008 already uses it by default for the “Paste Special…” command. Apparently, the script menu shortcuts supersede the built-in shortcuts. Yey. (I still removed the shortcut from the “Paste Special…” command, just in case.)
So there we are. I have a more or less functional “Paste without Formatting” command in Word, and I can use the same shortcut as in Pages. I guess I’ll just have to get used to the insertion point being at the beginning of the text after pasting. If anyone ever finds an easy way to move it to the end, please share!