An AppleScript to convert clipboard contents to plain text

Feb 11, '04 09:10:00AM

Contributed by: cfoster

I frequently find myself wanting to copy and paste text between two programs that use completely different styles for their text. The problem is that when I paste the text, it brings along the style of other program, which means I now have to change font, weight, size, etc. for the text to make it look like the text I'm pasting it beside. However, If you have quick access to AppleScripts through Apple's Script Menu or iKey, then the following line of AppleScript will remove the formatting and leave the plain text (which should then take on the default formatting of whatever program you are pasting it into):

set the clipboard to «class ktxt» of ((the clipboard as text) as record)
How it works: The as text portion grabs the stylized text from whatever other junk may be surrounding it (which can be significant). As record splits out the style and text portions, and »class ktxt» grabs the plain text portion of that.

[robg adds: Enter the above line in Script Editor and save it (I saved it as a compiled application, though I don't think this matters). Save it into your user's Library -> Scripts folder so that it's accessible everywhere. Then, when you have text to convert, just choose the script from the drop-down Script menu prior to pasting, and you'll get a nice plain-text paste.]

Comments (21)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040204170653788