Macotron

macotron.qr

Read a QR code from an image, from part of the screen, or from the camera, and make a QR code as a PNG or in a floating window.

macotron.plugin({
  title: "QR Code Tools",
  description: "Scan a QR code from the screen, or show one for the clipboard.",
  permissions: ["screenRecording", "camera"],
});

macotron.command("Scan QR from Screen", "Drag a box around a QR code", async () => {
  const text = await macotron.qr.scan();
  if (text) macotron.clipboard.set(text);
});

macotron.command("Show QR", "Show a QR code for the clipboard", () => {
  const text = macotron.clipboard.text();
  if (text) macotron.qr.show(text);
});

Reading codes

detect(opts: { path?: string; image?: string }): Promise<string | null>

Resolves with the payload of the first QR code in the image, or null when there is none. path is an image file (a leading ~ expands). image is base64 image data or a data: URL. When both are given, path wins. The call throws a TypeError when neither is usable.

Images larger than 8192 pixels on a side, or larger than 8 MB, resolve with null.

scan(opts?: { camera?, screenshot?, selection? }): Promise<string | null>

Lets the user point at a code, then resolves with its payload. It resolves with null when the user cancels or no code is found. One scan runs at a time; a second call while one is open resolves with null.

OptionDefaultMeaning
camerafalseOpens a camera preview window that closes when it sees a code. Cancel and Escape close it. This option overrides the other two.
screenshottrueReads the code from the screen.
selectiontrueWith screenshot, the user drags a box around the code. With false, it reads the whole display.

A screen scan needs Screen Recording permission, and a camera scan needs Camera permission. Put "screenRecording" or "camera" in the permissions of macotron.plugin(). A camera scan without access resolves with null.

Making codes

image(text: string, opts?: { size?: number }): string | null

A QR code for text as a base64 PNG, size pixels square. size defaults to 256 and is clamped to 32…2048. Returns null for empty text or text longer than 4096 characters.

show(text: string, opts?: { size?: number }): void

Shows a QR code for text in a floating window titled "QR Code". A second call reuses the same window. size sets the image resolution as in image(); the window stays 280 points square.

See also