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.
- Find the program you wish to operate on and make a copy of it.
- Open the package to the copy of the program and navigate to
Contents/Resources/YourLanguage.lproj and open MainMenu.nib in Interface Builder.
- Click on the “Edit” menu in the menu bar you’re editing.
- Click on the “Paste” item in the menu and press Command-I.
- Choose connections from the pop-up menu in the info window.
- If the connection in bold does not say
paste: then stop here. This will not work in this program.
- From the palette on the right, click on the menu icon in the toolbar.
- Drag the item from the palette that says “Item” to a place right under the
Paste item in the menu.
- 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.)
- 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.
- Control-drag (hold control and drag) from the item to the icon in the lower window called “First Responder” (a big tacky orange one).
- 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.
- Save.
- Quit.
- Open the copy of the program.
- Test.
- Enjoy.
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.
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).
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.
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
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).
To fix an app after this hack requires you to unarchive the backup copy I included instructions on making.
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