app.qrcode - QR Code API

QR code generation and recognition.

Generation

app.qrcode.generate(text, config?)

Generate a QR code image.

Parameters:

  • text (string) - text to encode
  • config (table):
    • path (string, required) - output image path
    • size (number, optional) - image size, default 256
    • correctionLevel (string, optional) - error correction level: "L", "M" (default), "Q", "H"
    • color (string, optional) - foreground color, "#RRGGBB" format
    • backgroundColor (string, optional) - background color, "#RRGGBB" format

Returns: boolean, error

-- Basic generation
app.qrcode.generate("https://example.com", {
    path = "/tmp/qr.png"
})

-- Custom style
app.qrcode.generate("https://example.com", {
    path = "/tmp/qr.png",
    size = 512,
    correctionLevel = "H",
    color = "#1A1A2E",
    backgroundColor = "#E0E0E0"
})

Recognition

app.qrcode.recognize(imagePath)

Recognize QR codes in an image.

Parameters:

  • imagePath (string) - image file path

Returns: array<table>, error - each item contains:

  • text (string) - decoded text
  • type (string) - type ("QRCode")
  • bounds (table) - position: {x, y, w, h}
local codes, err = app.qrcode.recognize("/path/to/image.png")
if codes then
    for _, code in ipairs(codes) do
        app.log.info("Content: " .. code.text)
    end
end

app.qrcode.recognizeFromScreen(options?)

Capture the screen and recognize QR codes.

Parameters:

  • options (table, optional):
    • displayId (number) - display ID
    • rect (table) - capture region: {x, y, w, h}

Returns: array<table>, error - same as recognize()

local codes = app.qrcode.recognizeFromScreen()
if codes and #codes > 0 then
    app.clipboard.setText(codes[1].text)
    app.notification.show("QR Code", "Copied: " .. codes[1].text)
end

Examples

Generate QR Code for Selected File

function MyPlugin:handleGenerateQR(context)
    local file = context.selectedFiles[1]
    local text = app.dialog.input("Enter content", app.path.basename(file))
    if not text then return end

    local qrPath = app.path.removeExtension(file) .. "_qr.png"
    local ok, err = app.qrcode.generate(text, {
        path = qrPath,
        size = 512,
        correctionLevel = "H"
    })

    if ok then
        app.notification.show("Done", "QR code generated")
        app.finder.reveal(qrPath)
    else
        app.dialog.alert("Error", err or "Generation failed")
    end
end

Recognize QR Code in Image

function MyPlugin:handleScanQR(context)
    local file = context.selectedFiles[1]
    local codes, err = app.qrcode.recognize(file)

    if not codes then
        app.dialog.alert("Error", err or "Recognition failed")
        return
    end

    if #codes == 0 then
        app.dialog.alert("Result", "No QR code found")
        return
    end

    local text = codes[1].text
    app.clipboard.setText(text)
    app.notification.show("QR Code", "Copied: " .. text)
end
Developer Documentation
User Guide
Getting Started Script Menus FAQ
Script Development
Development Guide
Plugin Development
Quick Start Development Guide Example Plugins
API Reference
Overview API Query Plugin Info Logging Finder Context Plugin Settings Internationalization
UI & Interaction
Dialog Progress Notification Chooser WebView Status Bar Dock
Files & Paths
File Operations Path Utilities Finder Actions Trash Extended Attributes Metadata File Watcher
Data Formats
JSON Plist CSV XML PDF Image
Text & Encoding
String Regex Date & Time Color Crypto
System
Shell Commands Process Application System Info AppleScript Shortcuts
System Info
Network Power/Battery Screen/Appearance Audio Bluetooth Location
Network
HTTP WebSocket URL
Input & Clipboard
Keyboard Mouse Hotkey Clipboard Window
Storage
SQLite Keychain UserDefaults
Media
OCR QR Code
Utilities
Archive UTI Share Timer Wake Lock Thread