Text Editing & Formatting

Outdent

Remove the shared indentation from selected lines.

OfficialOn-device

Download action

What Outdent does

Remove the shared indentation from selected lines. 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

Outdent example
ActionOutcome
OutdentSelected text: one two threeone two three

Use Outdent

Follow these steps to remove the shared indentation from selected lines with ActionClip.

  1. Select the text you want to use.
  2. Choose Outdent 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) {
  var normalized = selected_text.replace(/\r\n?|\u2028|\u2029|\u0085|\u000B|\u000C/g, "\n");
  var lines = normalized.split("\n");
  var nonBlank = lines.filter(function (line) { return /\S/u.test(line); });
  if (nonBlank.length === 0) return normalized;
  var width = nonBlank.reduce(function (shortest, line) {
    var prefix = (line.match(/^[ \t]*/u) || [""])[0];
    return Math.min(shortest, prefix.length);
  }, Number.MAX_SAFE_INTEGER);
  if (!Number.isFinite(width) || width === 0) return normalized;
  return lines.map(function (line) { return /^\s*$/u.test(line) ? "" : line.slice(width); }).join("\n");
}