Supertip: Be a TextEdit Power User – Mac Kung Fu, 2nd Edition

Tip 383Supertip: Be a TextEdit Power User

As its name suggests, TextEdit started life as a simple text-editing application. However, it has grown into a fully fledged word processor to the extent where it’s good enough for light to moderate use. It can be found within the Applications list of Finder, and here are a few tips to help you get the very best out of it.

Type and Spell-Check Foreign Languages

This is less of a tip and more of an observation, although it’s worth knowing. If you start typing in a non-English language, TextEdit will automatically switch its spell-check dictionary to that language. Start typing in German, for example, and it will spot any errors in the German words you type. Right-clicking a misspelled word underlined in red will bring up a list of suggested German-language corrections.

Start typing in English, however, and TextEdit will again realize and switch the dictionary for that particular part of the document to English.

Go to a Particular Line

There’s a hidden keyboard shortcut within TextEdit that lets you jump straight to a particular line number. This can be useful for programmers, even though there is no option within TextEdit to actually display line numbers! To jump to a particular line, just hit Command+L, and then type the number in question.

Copy the Font Style of Some Text

Let’s say you’re working on a complicated document in TextEdit and want to add a paragraph. However, you also want to copy the same font and style as a paragraph earlier in the document. Simply place your cursor within the older paragraph, and hit Option+Command+C. Then place the cursor where you’d like to type, and hit Option+Command+V. If you start typing, you should find it matches the font and style.

Search Better

If you search for a word or phrase in TextEdit, you’ll see that the document view is dimmed, and any instances of the search term are picked out in stark white. Additionally, you can click the left and right arrow buttons in the Find toolbar to move a yellow “blob” highlight through the document that shows instances of the search term.

The problem is that the yellow “blob” expands beyond the boundaries of the word or phrase and covers letters to the left and right, which can make it difficult to see whether this particular instance of the found search term is the one you’re looking for.

The solution is to click anywhere within the document. This will deactivate the screen dimming. The search toolbar won’t disappear, and if you keep using the left and right arrows to find the search term, the yellow blob will contract to a simple highlight of the word or phrase, within a second or two of finding it. It’s a subtle but useful difference.

Replace Text Within a Selection

At first glance, TextEdit doesn’t seem to offer any way of replacing text within a selection you’ve made in a document. However, if you hold the All button on the Find/Replace toolbar, a pop-out menu will offer the option. See Figure 57, Replacing text within a selection in TextEdit for an example.


Figure 57. Replacing text within a selection in TextEdit

Add Word Counting

TextEdit lacks one key feature that students and professional writers might miss: word count.

This feature can be added using a little AppleScript, as follows (with many thanks to tip creator Mike Riley, author of fellow Pragmatic Bookshelf title Programming Your Home):

  1. Open a Terminal window (open Finder, select the Applications list, and then in the list of applications double-click Terminal within the Utilities folder), and then type the following:

     
    mkdir ~/Library/Scripts/

    Close the Terminal window.

  2. Start AppleScript Editor, which you’ll find in the Utilities folder within the Applications view of Finder.

  3. Click the program’s menu, and then select the Preferences entry. In the dialog box that appears, ensure the General tab is selected, and check the Show Script Menu in Menu Bar heading. This will add a new icon to the top right of the screen, which you can ignore for the moment. Close the Preferences dialog box.

  4. Back in the main AppleScript Editor window, type the following code:

     
    tell application "TextEdit"
     
    set wc to count words of document 1
     
    if wc is equal to 1 then
     
    set txt to " word."
     
    else
     
    set txt to " words."
     
    end if
     
    set result to (wc as string) & txt
     
    display dialog result with title "Word Count" buttons {"OK"} default
     
    button "OK"
     
    end tell
  5. Click the Compile button on the toolbar to check the code. If you get an error, check to ensure you’ve typed everything correctly. If everything is fine, you should see that AppleScript reformats the code slightly so it’s easier to read—this is fine and can be ignored.

  6. Click FileSave. In the Save As dialog box, hit Shift+Command+G; then type ~/Library/Scripts/, and hit the Go button.

  7. Give the script the filename Word Count, and then click the Save button.

  8. Quit AppleScript Editor.

If you want to perform a word count on a document when using TextEdit, click the new Scripts icon at the top right of the screen, and click the Word Count entry, which will probably be at the bottom of the list.

To remove the word count feature, open a Finder window, hit Shift+Command+G, and then enter ~/Library/Scripts/, before hitting the Go button. Then delete the Word Count file. Open AppleScript Editor once again, open its Preferences dialog box, and remove the check next to Show Script Menu in Menu Bar.

Copy a Ruler from One Doc to Another

Did you know that you can copy a ruler within TextEdit, complete with a set of tabs you might have created, from one document to another? Or from one place in a document to a later or earlier position? Just hit Control+Command+C to copy the ruler; then, after positioning the cursor where you want to apply the rule, hit Control+Command+V. Alternatively, you can click the options on the FormatFont menu.

Create a New Document from a Text Selection

Ever wanted to instantly create a new document within TextEdit from text you’ve selected? For example, if you’re writing a letter and want to create a nearly identical duplicate, you could highlight the text you want to be in the duplicate and then hit a keyboard shortcut to instantly create a new document containing it.

OS X makes it easy to set up a new keyboard shortcut and menu option to allow just this, as follows:

  1. Open System Preferences (Apple menuSystem Preferences), and click the Keyboard icon. Then select the Keyboard Shortcuts tab.

  2. Select the Services heading in the list on the left.

  3. Scroll down the list on the right to the Text heading. Underneath this, several entries down in the list, will be New TextEdit Window Containing Selection (although it might appear truncated as “New TextEdt Window Contai...”). Check it. This will add it to the menu that appears when you right-click text in TextEdit.

  4. If you’d also like to assign a keyboard shortcut, click the small, almost invisible, word none at the right of the line within the list. Then click the Add Shortcut button that appears. Adding shortcuts can be tricky because you mustn’t use a shortcut already in use.[40] In this case, I find that Control+Option+Command+N works well.

  5. Restart TextEdit for the changes to take effect.

You can now right-click selected text and select New TextEdit Window Containing Selection from the menu that appears, or you can select text and hit Control+Option+Command+N.

To deactivate the function later, repeat the previous steps, but simply remove the check alongside the TextEdit Window Containing Selection entry in the list within System Preferences. You’ll have to restart TextEdit for the changes to take effect.

Instantly Zoom In or Out

If you have a trackpad, you can zoom in or out in TextEdit using the pinch-to-expand gesture (that is, placing your finger and thumb together on the trackpad and moving them apart; contracting them again will zoom out).

Change Page Color

You can switch the page color in TextEdit by opening the Text palette (Command+T) and then clicking the fourth icon from the left on the palette—the one that looks not unsurprisingly like a page icon! Then just select a color from the pinwheel that appears. It will be applied instantly.

Note that the page color is merely for your viewing ease and pleasure. Although the color choice will be saved with the document and will reappear when you open the document in the future, the background color won’t appear when the document is printed. Nor will it appear if the document is opened in any other word processor apart from TextEdit. Currently there’s no way to implement background colors within TextEdit.

Note that this same trick works when writing an email, although you must first click within the body of the email before bringing up the Color palette. Unlike with TextEdit, the background color will appear in mails sent to other Macs (and if the mail is viewed by http://icloud.com), but in my tests it didn’t appear if the email was viewed using Microsoft Windows email clients. Therefore, you should be careful if you select to use white text against a dark background color—for any recipients of your email using Windows, the mail will appear to be white text against a white background and therefore be unreadable!