Wrap Text At Selectable Width [Macro:KM10]

This utility copies the selected text and performs a text wrap function by leveraging the command line utility "fold" provided in macOS, and puts the result in the clipboard.

I provide two methods user can use:

  • By Dialog
    Setup width by config dialog, and shortcut key will copy and process the text into clipboard

  • By Context Menu
    This is a dynamic and enhanced version whereby the default width is setup by long-pressed shortcut key, and if text is selected, will copy and process the text into clipboard. Shortcut Key without delay will perform similarly using default width


Method 1: Wrap Text At Selectable Width By Dialog
For setup, please select the width by activating shortcut key when mouse is top of screen.

image

[GBL] Wrap Text At Selectable Width.kmmacros (5.8 KB)


Method 2: Wrap Text At Selectable Width By Context Menu
User select default width by long-pressed shortcut-key. After width is selected, the macro will detected if there is selected text, with which it will proceed to process the copied text.
Shortcut Key without delay will perform similarly using default width.

[GBL] Wrap Text At Selectable Width (By Context Menu).kmmacros (6.1 KB)

3 Likes

Thank you very much for your macros.

Is it conceivable to create a macro which would both wrap and shrink text so that it fits in a box of predetermined height and width?

For height, you can get output text and truncate it to desired row length.

You need to pipe to head command after creating the input field for the height.

fold -w "$KMVAR_wrapText_width" -s |  head -n "$KMVAR_wrapText_height"
1 Like

OK thank you