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)

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)

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

Toggle Comments.shortcut (22.5 KB)

Highly recommend PopClip

Contains tons of preMade extensions to either perform actions with selected text or manipulate it.

Supports AppleScript, Java, Shell scripts.
Easily write your own extensions

I edited three of the above shortcuts to fix issues. The following shortcuts number or add bullets to the beginning of paragraphs of selected text. Paragraphs that are blank or that contain whitespace only are skipped.

Bullet Text.shortcut (23.1 KB)

Number Text.shortcut (23.1 KB)

The following shortcut sorts paragraphs of selected text alphabetically. Paragraphs that are blank or that contain whitespace only are deleted.

Sort Text.shortcut (22.5 KB)