Macotron

macotron.screen

Capture the whole display or a region the user drags, as a base64 PNG, and pick a color from anywhere on screen.

macotron.plugin({
  title: "OCR",
  description: "Drag a box on screen and copy the text inside it.",
  permissions: ["screenRecording"],
});

macotron.command("OCR Selection", "Copy the text in a dragged box", async () => {
  const image = await macotron.screen.capture({ selection: true });
  if (!image) return; // the user pressed Escape
  macotron.clipboard.set(await macotron.ocr.recognize({ image }));
});

Capture

Capture needs Screen Recording permission. Put "screenRecording" in the permissions of macotron.plugin() so the user can grant it from the plugin's Settings page.

capture(opts?: { selection?: boolean }): Promise<string>

Resolves with a base64 PNG at the display's full pixel resolution. Without options, it captures one whole display: the first display that macOS lists.

With selection: true, the screen dims and the user drags a rectangle. The PNG holds only that rectangle. Escape, or a drag smaller than 8 points on a side, cancels, and the promise resolves with "".

The promise rejects when the capture fails, for example when Screen Recording permission is missing.

Color picker

pickColor(): Promise<{ hex, r, g, b, x, y } | null>

Opens the system magnifier eyedropper. When the user clicks, it resolves with the color in sRGB: hex is "#RRGGBB", and r, g, b are 0…255. x and y are where the pointer was, in Cocoa screen points (the origin is the bottom-left of the main display). Resolves with null when the user presses Escape.

The eyedropper does not need Screen Recording permission.

const color = await macotron.screen.pickColor();
if (color) macotron.clipboard.set(color.hex);

See also