Developer Tools

Base64 Encode

Encode selected Unicode text as Base64 UTF-8.

OfficialOn-device

Download action

What Base64 Encode does

Converts Unicode to UTF-8 bytes and emits standard padded Base64 without relying on browser or Node.js APIs.

CategoryDeveloper Tools
Action typeJavaScript
ResultReplace or copy text
InternetNot required

Action and outcome

Base64 Encode example
ActionOutcome
Base64 EncodeSelected text: ActionClipQWN0aW9uQ2xpcA==

Use Base64 Encode

Follow these steps to encode selected Unicode text as Base64 UTF-8 with ActionClip.

  1. Select the text you want to use.
  2. Choose Base64 Encode from ActionClip.
  3. Review the result, then replace the selection or copy the new text.

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 configuration

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

JavaScript definition
function run(selected_text) {
  const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  const bytes = [];

  for (let index = 0; index < selected_text.length; index += 1) {
    let codePoint = selected_text.charCodeAt(index);
    if (codePoint >= 0xD800 && codePoint <= 0xDBFF) {
      const low = selected_text.charCodeAt(index + 1);
      if (low >= 0xDC00 && low <= 0xDFFF) {
        codePoint = 0x10000 + ((codePoint - 0xD800) << 10) + (low - 0xDC00);
        index += 1;
      } else {
        codePoint = 0xFFFD;
      }
    } else if (codePoint >= 0xDC00 && codePoint <= 0xDFFF) {
      codePoint = 0xFFFD;
    }

    if (codePoint <= 0x7F) {
      bytes.push(codePoint);
    } else if (codePoint <= 0x7FF) {
      bytes.push(0xC0 | (codePoint >> 6), 0x80 | (codePoint & 0x3F));
    } else if (codePoint <= 0xFFFF) {
      bytes.push(0xE0 | (codePoint >> 12), 0x80 | ((codePoint >> 6) & 0x3F), 0x80 | (codePoint & 0x3F));
    } else {
      bytes.push(0xF0 | (codePoint >> 18), 0x80 | ((codePoint >> 12) & 0x3F),
        0x80 | ((codePoint >> 6) & 0x3F), 0x80 | (codePoint & 0x3F));
    }
  }

  let output = "";
  for (let index = 0; index < bytes.length; index += 3) {
    const first = bytes[index];
    const second = index + 1 < bytes.length ? bytes[index + 1] : 0;
    const third = index + 2 < bytes.length ? bytes[index + 2] : 0;
    const value = (first << 16) | (second << 8) | third;
    output += alphabet[(value >> 18) & 63];
    output += alphabet[(value >> 12) & 63];
    output += index + 1 < bytes.length ? alphabet[(value >> 6) & 63] : "=";
    output += index + 2 < bytes.length ? alphabet[value & 63] : "=";
  }
  return output;
}