|
Text Substitution
|
|
You can define abbreviations with corresponding substitutions; when you type an abbreviation, Script Debugger replaces it with the substitution. This can be a convenient way to enter boilerplate text, commonly used control structures and commands, or characters that are difficult to type directly; you might also use it as a form of automatic spelling correction.
This feature is turned on through a preference, and managed in the same preference pane:
To turn on text substitutions, check Automatic Substitution: Enabled in the Text Substitutions preference pane.
To use a text substitution, once this feature has been turned on, just type. For example, in a script, type teh and a space character; Script Debugger corrects teh to the. The rule is that when you type a sequence of characters, then when you type a following non-word character, such as a space, a tab, a Return, a comma, and so on, Script Debugger looks to see whether the preceding characters are an abbreviation; if they are, it automatically replaces them with the substitution.
To manage text substitutions, edit the list in the Text Substitutions preference pane. Use the + button to create a new substitution; use the - button to delete a selected substitution. Double-click in the Replace or With column to edit text. Even if text substitutions as a whole are turned on, you can disable an individual substitution by unchecking it in the On column.
What you are managing here are text pairs. The Replace column is the text you will type (the abbreviation); the With column is the text that Script Debugger will replace it with (the substitution).
Script Debugger ships with some text substitutions included, and they illustrate various uses of this feature. For example:
You can type dd (plus space) to get display dialog "message", a convenient way to enter a commonly used command.
You can type != (plus space) to get ≠; this corrects a common error (many languages use != as the not-equal operator, but AppleScript does not) and also helps enter a difficult character (many users can’t remember how to type ≠).
You can type teh (plus space) and get the; this corrects a common typo.
Observe that the substitution for dd includes the phrase [[select:message]]. This works just as for clippings: it means that when this substitution is performed, the word message will appear and will be selected. This is very convenient because it means you can type rapidly and continuously. To enter display dialog "howdy" you just type dd[space]howdy and the right thing happens.
The substitution idd demonstrates that text substitutions can consist of multiple lines of code. (Try it in a script window!) If you find that the preference pane is not a convenient place to edit a multi-line text substitution, edit the substitution in a script window or a word processor and paste it into the With column.
Text substitutions are quite analogous to clippings; indeed, they can be thought of as a convenient way to enter clippings. Text substitutions use the same expansion tags as clippings. Like clippings, text substitutions constitute boilerplate text that you’re entering with a single command. With a clipping, that command is a menu choice, or its keyboard shortcut. With text substitution, the command is the abbreviation, which you type directly into your script. In many cases, an abbreviation is easier to remember or to type.