Shortcuts that manipulate selected text

You can invoke a shortcut by way of an app’s Services menu, and this allows the user to run a shortcut on text selected in many apps. For example, the following shortcut replaces left and right quotation marks with regular quotation marks. It also removes all whitespace before and after each paragraph.

Clean Text.shortcut (22.0 KB)

The following shortcut sorts selected text:

Sort Text.shortcut (21.8 KB)

The following shortcut numbers selected text:

Number Text.shortcut (22.1 KB)

These shortcuts will show in an app’s Services menu only if text is selected.

These shortcuts worked reliably on my Sonoma computer with TextEdit, IA Writer Classic, Notes, FSNotes, Stickies, and Script Editor. The shortcut worked with Script Debugger except that the Clean Text shortcut would not remove leading whitespace. The shortcut did not work reliably with the Mail app.

The following is a revision of the Number Text shortcut. It differs in that it removes all leading whitespace from selected text, and it does not number any paragraphs that are blank or contain whitespace only.

Number Text.shortcut (22.8 KB)

This shortcut is similar to that above, differing in that a bullet character instead of a number is added to the beginning of each paragraph of selected text.

Bullet Text.shortcut (22.6 KB)

This shortcut works as a toggle to add or remove comment characters from the start of lines of selected text. It is intended for use with Script Debugger, Script Editor, Script Geek, and the like.

Toggle Comments.shortcut (22.4 KB)

Occasionally a forum member will post a script without the required code formatting (3 backtick characters), which can cause errors. This shortcut fixes some of those errors by replacing:

  • left and right single quotation marks with single quotes;

  • left and right double quotation marks with double quotes; and

  • en dashes with two consecutive dashes.

Please note:

  • The shortcut trims whitespace from the beginning and end of each paragraph, but this can be removed.

  • I tested this shortcut on the script in post 9 of the thread (here).

  • The shortcut is probably best run by way of the app’s Services menu. Text must be selected in the app for the shortcut to be visible in the Services menu.

Clean Script.shortcut (22.2 KB)