Text Editing & Formatting

Underscore Toggle

Switch spaces and underscores on each selected line.

OfficialOn-device

Download action

What Underscore Toggle does

Switch spaces and underscores on each selected line. It runs locally and handles the selected text without contacting a service.

CategoryText Editing & Formatting
Action typeJavaScript
Default resultReplace selected text by default
InternetNot required

Action and outcome

Underscore Toggle example
ActionOutcome
Underscore ToggleSelected text: one two three_fourone_two three four

Use Underscore Toggle

Follow these steps to switch spaces and underscores on each selected line with ActionClip.

  1. Select the text you want to use.
  2. Choose Underscore Toggle from ActionClip.
  3. In editable text, ActionClip replaces the selection immediately. In read-only text, it opens the result for review and copying.

Requirements and privacy

  • Before you start: No setup required.
  • Your selected text: Runs locally in ActionClip’s JavaScript sandbox. Selected text does not leave your Mac.

Action script

The script below is included so you can inspect how the action works before downloading it.

JavaScript definition
function run(selected_text) {
  return selected_text.replace(/^(\s*)(.*?)(\s*)$/gm, function (_, before, content, after) {
    if (/[^\S\r\n]/u.test(content)) {
      return before + content.replace(/[^\S\r\n]+/gu, "_") + after;
    }
    return before + content.replace(/_+/gu, " ") + after;
  });
}