blog advertising is good for you


blog advertising is good for you
User login

Paste as Plain Text, Dagnabbit!

Copy a clip from a web page in Safari. Paste it in iChat to send to a friend. Oh, now, what? The web designer used white text on black, but Safari didn’t copy the black? No matter, you’ve hacked iChat to support “Paste as Plain Text” haven’t you? Haven’t you?

Here’s a quick rundown for non-programmers: every menu item is connected to a function/method/action/thinggy in code that makes it do something. Cocoa, being wonderful, has about 100 of these built-in. In addition to the standard paste: method there are two others: pasteAsPlainText: and pasteAsRichText:. Now for the developers in the crowd you know exactly where I’m heading. Go, do it, have fun, you’re welcome. Everyone else, install the Developer Tools if you haven’t and then keep reading.

  1. Find the program you wish to operate on and make a copy of it.
  2. Open the package to the copy of the program and navigate to Contents/Resources/YourLanguage.lproj and open MainMenu.nib in Interface Builder.
  3. Click on the “Edit” menu in the menu bar you’re editing.
  4. Click on the “Paste” item in the menu and press Command-I.
  5. Choose connections from the pop-up menu in the info window.
  6. If the connection in bold does not say paste: then stop here. This will not work in this program.
  7. From the palette on the right, click on the menu icon in the toolbar.
  8. Drag the item from the palette that says “Item” to a place right under the Paste item in the menu.
  9. Double-click on it and name it something like Paste with Current Style or Paste as Plain Text or Twinkle, twinkle little star or something. (Calling it “Paste as Plain Text” now will make it a little easier later.)
  10. Double-click right on the area directly under the keyboard shortcut of the previous item, even if text is there. When you get a box, press the keys you want to activate this. I suggest Command-Shift-V.
  11. Control-drag (hold control and drag) from the item to the icon in the lower window called “First Responder” (a big tacky orange one).
  12. In the Info window that just came up, scroll to pasteAsPlainText: and double-click on it. If you named it “Paste as Plain Text” earlier then it should auto-select this method.
  13. Save.
  14. Quit.
  15. Open the copy of the program.
  16. Test.
  17. Enjoy.
Average rating
(0 votes)
About Adam Knight
Adam Knight's picture

Author Biography

Adam Knight is one of the founders of Mac Geekery and is a geek at heart. Programmer by day, hacker by night, his daily life revolves around the Macintosh platform, which he has been a user and programmer for since the early days of System 7 when his LCII replaced his Apple //c.

In-between tech jobs, he’s managed to learn the basics of any web hacker: PHP, MySQL, Perl, Apache, Linux, *BSD, and the intricacies of ./configure —prefix=~/bombshelter/. Today, codepoet is concentrating on blogging again, writing some software for the Mac by himself (including Notae) and for his company (such as Switchblade) and has a few other toys coming out soon.

Bug him over AIM or email [link fixed].

Nice hack. One minor tweak: the shortcut to open Interface Builder’s Info palette is Shift-Cmd-I, not Cmd-I.

i use a paste as plain text applescript:
http://www.macosxhints.com/article.php?story=20040204170653788

Nice job. One thing you should add is – If the connection “paste” does not show up, make sure the “Target/Action” tab of the Info panel is selected and not the “Outlets” tab.

Most applications store their menu bar in MainMenu.nib, but not all (for an example, see TextEdit). To find out for sure what nib file you need to edit, you can look in the application’s Info.plist in its Contents folder. Search for “NSMainNibFile” and you’ll find the name of the nib file there.

pasteAsPlainText: pastes "as current style" in the most current versions of Mail and TextEdit. And yes, I double checked the action setting. It seems that the pasteAsPlainText: action can be listed, but not always implemented as advertised.
Adam Knight's picture

Mail and TextEdit already implement this, so there’s no need for it. It’s listed as “Paste With Current Style” and is Cmd-Shift-Opt-V.

cp

It doesn’t work in iChat 2.1 in OS X 10.3.5. The new menu item is linked to the pasteAsPlainText: action, but selecting the command still pastes the clipboard text as styled (bold, when I tested it).

Adam Knight's picture

It works fine on three computers here and countless others, so ya did something wrong.

Make sure you’re adding a new item, giving it a different keyboard shortcut than the normal Paste option, and verify that when you click on the new menu item that the connection is pasteAsPlainText:

cp

…it works sometimes. If I open a new iChat window and Paste as Plain Text, it works.
But if I perform the following, it pastes the clipboard as styled text: – Paste (as styled text) – Undo – Paste as Plain Text

And I’ve also noticed that it fails in other circumstances when bold text is on the clipboard. Sometimes opening a NEW iChat window and selecting Paste as Plain Text still inserts the clipboard text as bold.

I’m having trouble reproducing the exact steps, but play around with it. Something’s broken with this procedure.

Adam Knight's picture

Well, it’s not the procedure, it’s how Mac OS X handles undo/redo and the clipboard (i.e. badly). I’ve had similar problems in other programs as well. All this procedure does is add a standard menu item, the rest is up to Cocoa.

cp

What about this? plaintextpaste
Adam Knight's picture

I’d really rather not make a runtime patch to every program I run just to get one command in two programs I use… :\


cp

But you wouldn’t mind making a permanent modification to the apps instead? The benefit of SIMBL is that you can edit the bundle’s Info.plist to force it to only operate on specified apps. Removing the bundle will immediately return the apps to normal. To fix apps after this hack requires a reinstall (not that such a simple modification, in either the permanent or temporary form, is very dangerous).

Adam Knight's picture

To fix an app after this hack requires you to unarchive the backup copy I included instructions on making. Sticking out tongue

As for SIMBL, I treat it like App Enhancer or any other runtime hack: folks who can’t get go of Mac OS 9’s extensions treading into my Mac OS X world. Editing the NIB is one thing, and it’s not dangerous as long as you have a backup and works in any program that uses Paste properly. Runtime gadgets can cause application instability. I don’t know about this one, but the sheer aspect of possibly creating instability in my programs is enough to make me avoid it. That’s why I happily don’t use Mac OS 9 anymore; the idea of runtime patching is ancient and outdated.

Unless you’re using LISP, and then that’s a whole other story.

cp

I’ve tried what you told and it really worked. You save me so much time for changing the text color in Safari.

Post new comment
The content of this field is kept private and will not be shown publicly.
1 + 15 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.