Affinity Designer Automation: Scripting, Macros, and AI-Driven Workflows

Matthew Diakonov··13 min read

Affinity Designer Automation: Scripting, Macros, and AI-Driven Workflows

Affinity Designer is one of the best vector design tools available, especially on macOS. It handles complex illustrations, UI mockups, and icon sets with ease. The problem is automation. Unlike Adobe Illustrator, which offers ExtendScript, CEP panels, and UXP plugins, Affinity Designer has no public scripting API, no plugin architecture, and no CLI. If you need to batch export 200 icon variants, apply consistent style changes across dozens of artboards, or generate assets from a data source, you have to get creative.

This guide covers every practical approach to automating Affinity Designer workflows on macOS, from the built-in macro system to external tools that control the app through accessibility APIs and AI agents.

Affinity Designer's Built-in Macro System

Affinity Designer 2 ships with a macro recorder. Open the Macro panel (View > Studio > Macro), click Record, perform your operations, stop recording, and save.

What macros can do

  • Apply fill and stroke changes across selected objects
  • Run non-destructive adjustments and filters
  • Execute transformation sequences (scale, rotate, skew)
  • Replay sequences across multiple objects or layers

What macros cannot do

  • Open or close files
  • Navigate between artboards or documents
  • Export with specific settings
  • Interact with the file system
  • Accept parameters or conditional logic
  • Run from the command line or a script

| Capability | Affinity Designer Macros | Illustrator ExtendScript | |---|---|---| | Record and replay edits | Yes | Yes (Actions + scripting) | | File I/O (open, save, export) | No | Yes | | Conditional logic | No | Yes | | Loop over objects | No | Yes | | CLI invocation | No | Yes | | Third-party plugin hooks | No | Yes (CEP/UXP) | | Cross-document operations | No | Yes |

Macros are useful for repetitive styling tasks on a single document, but they fall short the moment you need anything that touches the file system or requires logic.

AppleScript and macOS Accessibility Automation

Since Affinity Designer does not expose a scripting dictionary for AppleScript, you cannot call application-specific commands like tell application "Affinity Designer 2" to export artboard 1. However, macOS accessibility APIs (via System Events) let you drive the UI programmatically.

Basic AppleScript UI automation

tell application "Affinity Designer 2" to activate
delay 0.5

tell application "System Events"
    tell process "Affinity Designer 2"
        -- Open Export Persona via menu
        click menu item "Export Persona" of menu "View" of menu bar 1
        delay 1

        -- Click the "Export" button in the Export Persona toolbar
        click button "Export" of toolbar 1
        delay 0.5
    end tell
end tell

This approach is brittle. Menu item names change between versions, toolbar layouts shift, and timing depends on system load. But for simple sequences (open export persona, click export, confirm dialog), it works reliably enough for small batches.

Automator and Shortcuts integration

macOS Shortcuts (and the older Automator) can chain AppleScript blocks with file system operations. A practical workflow:

  1. Use a "Get Folder Contents" action to list .afdesign files
  2. For each file, run an AppleScript block that opens it in Affinity Designer
  3. Trigger the export macro via UI scripting
  4. Wait for the export to complete, then close the document
# List all .afdesign files in a directory
find ~/Design/Icons -name "*.afdesign" -type f

The main limitation is speed. UI automation through accessibility APIs runs at human speed (each click takes 0.3 to 1 second with delays for UI response), so processing 200 files takes 15 to 30 minutes depending on complexity.

Shell Scripting for Batch Export

Affinity Designer does not have a CLI, but you can combine open commands with AppleScript UI automation to build a batch pipeline:

#!/bin/bash
# Batch export all .afdesign files to PNG via UI automation

EXPORT_DIR="$HOME/Design/Exports"
mkdir -p "$EXPORT_DIR"

for file in ~/Design/Icons/*.afdesign; do
    filename=$(basename "$file" .afdesign)
    echo "Processing: $filename"

    # Open the file
    open -a "Affinity Designer 2" "$file"
    sleep 3

    # Run the export AppleScript
    osascript -e '
    tell application "System Events"
        tell process "Affinity Designer 2"
            keystroke "e" using {shift down, option down, command down}
            delay 2
        end tell
    end tell
    '

    # Close without saving
    osascript -e '
    tell application "Affinity Designer 2"
        close front document saving no
    end tell
    '
    sleep 1

    echo "Done: $filename"
done

Warning

The keyboard shortcut for "Export" varies between Affinity Designer versions and user configurations. Check your actual shortcut in the File menu before running this script. The default on Affinity Designer 2.x is usually Shift+Option+Cmd+E for slice export.

SVG as an Automation Escape Hatch

One of the most effective automation strategies with Affinity Designer involves exporting to SVG and manipulating the XML directly. SVG is a text format, so every standard text processing tool works on it.

Batch color replacement

#!/bin/bash
# Replace a brand color across all exported SVGs

OLD_COLOR="#FF6B35"
NEW_COLOR="#14b8a6"

for svg in ~/Design/Exports/*.svg; do
    sed -i '' "s/$OLD_COLOR/$NEW_COLOR/gi" "$svg"
    echo "Updated: $(basename "$svg")"
done

Generating icon variants from a template

import xml.etree.ElementTree as ET
import copy

# Load the base SVG exported from Affinity Designer
tree = ET.parse("icon-template.svg")
root = tree.getroot()

colors = {
    "primary": "#14b8a6",
    "secondary": "#0d9488",
    "dark": "#0f172a",
    "light": "#e2e8f0"
}

for name, color in colors.items():
    variant = copy.deepcopy(root)
    # Find all elements with fill attribute and replace
    for elem in variant.iter():
        if elem.get("fill") == "#000000":
            elem.set("fill", color)
    new_tree = ET.ElementTree(variant)
    new_tree.write(f"icon-{name}.svg", xml_declaration=True)
    print(f"Generated: icon-{name}.svg")

This "export once, transform many" pattern sidesteps Affinity Designer's automation limitations entirely. Design the master asset in the GUI, export to SVG, then let scripts handle the variations.

AffinityDesignerExportSVG/PNGScriptTransformNVariantsDesign once in the GUI, export to SVG, then generate variants with scripts

AI Desktop Agents for Affinity Designer

The newest approach to automating apps without APIs is AI desktop agents. These agents observe the screen (via screenshots or accessibility trees), understand what they see, and execute actions through mouse clicks and keyboard input, exactly like a human would, but driven by an LLM.

How AI agents interact with Affinity Designer

An AI agent targeting Affinity Designer typically:

  1. Reads the screen state via macOS accessibility APIs or screenshots
  2. Identifies UI elements (menus, panels, buttons, layers list)
  3. Plans a sequence of actions to accomplish the task
  4. Executes clicks, keyboard shortcuts, and drag operations
  5. Verifies the result by reading the updated screen state

This is fundamentally different from macro recording. A macro replays a fixed sequence. An AI agent adapts to what it sees, meaning it can handle dialogs that appear unexpectedly, find buttons that moved to a different position in a UI update, or recover from errors.

Practical use cases for AI agents with Affinity Designer

| Task | Traditional automation | AI agent approach | |---|---|---| | Batch export 100 artboards | AppleScript UI scripting (fragile) | Agent navigates Export Persona, handles dialogs | | Apply consistent styles | Macros (no file I/O) | Agent opens files, applies changes, saves | | Generate asset variations | SVG post-processing | Agent modifies designs directly in the app | | Complex multi-step workflows | Chained scripts (brittle) | Agent handles the full sequence with error recovery | | Cross-app pipelines | Multiple scripts + glue code | Single agent drives Designer + other tools |

Tip

AI desktop agents work best for workflows that are too complex for simple macros but too infrequent to justify building a full automation pipeline. If you run the same export sequence twice a week, an agent that reads the screen and clicks through it is more maintainable than a 200-line AppleScript that breaks every time Serif updates the UI.

Setting up an AI agent for Affinity Designer on macOS

The key requirement is macOS accessibility permissions. The agent process (or its host app) needs to be added to System Settings > Privacy & Security > Accessibility. Without this, the agent cannot read UI element trees or send synthetic click events.

# Verify accessibility access for a process
tccutil check Accessibility com.example.agent-app

# Check if Affinity Designer is running and get its PID
pgrep -f "Affinity Designer"

# Dump the accessibility tree for debugging
# (requires accessibility permission)
xcrun swift -e '
import AppKit
let app = NSWorkspace.shared.runningApplications.first {
    $0.localizedName == "Affinity Designer 2"
}
print(app?.processIdentifier ?? "Not running")
'

Common Pitfalls

  • Relying on pixel coordinates for UI automation. Affinity Designer's layout changes with window size, panel visibility, and display scaling. Use accessibility element identifiers or menu paths instead of absolute coordinates.

  • Not accounting for modal dialogs. Export operations, save confirmations, and missing font warnings all produce modal dialogs that block automation. Your script or agent must handle these, or the entire batch stalls on file 3 of 200.

  • Overcomplicating when SVG post-processing would suffice. If your "automation" is really just changing colors, sizes, or text in exported assets, skip the UI automation entirely. Work with SVG files directly using sed, Python, or any XML tool.

  • Ignoring Affinity Designer's macro system for simple cases. For tasks that stay within a single document and do not need file I/O (applying a filter stack, adjusting curves, resizing selected objects), the built-in macro recorder is simpler and more reliable than any external tool.

  • Running UI automation at full speed. Affinity Designer needs time to render after each operation. Skip delays and you will get stale screenshots, missed clicks, and corrupted exports. A 0.5 to 1 second delay between actions is the safe minimum for complex operations.

Quick Reference: Choosing Your Automation Approach

What needs automating?Style/filter editsBatch file operationsComplex multi-stepUse MacrosSVG Post-ProcessingAppleScript + ShellAI Desktop AgentComplexity increases left to right.Start with the simplest approach that covers your use case.

Minimal Working Example: Batch SVG Color Swap

This is the simplest automation you can set up today. Design your icons in Affinity Designer, export them as SVG, then run this script to generate color variants:

#!/bin/bash
# batch-color-swap.sh
# Usage: ./batch-color-swap.sh input_dir output_dir old_color new_color

INPUT_DIR="${1:?Usage: $0 input_dir output_dir old_color new_color}"
OUTPUT_DIR="${2:?}"
OLD_COLOR="${3:?}"
NEW_COLOR="${4:?}"

mkdir -p "$OUTPUT_DIR"

count=0
for svg in "$INPUT_DIR"/*.svg; do
    [ -f "$svg" ] || continue
    name=$(basename "$svg")
    sed "s/$OLD_COLOR/$NEW_COLOR/gi" "$svg" > "$OUTPUT_DIR/$name"
    count=$((count + 1))
done

echo "Processed $count files: $OLD_COLOR -> $NEW_COLOR"
echo "Output: $OUTPUT_DIR"
# Example: swap black icons to teal
./batch-color-swap.sh ./icons ./icons-teal "#000000" "#14b8a6"

Wrapping Up

Affinity Designer was not built for automation, but that does not mean your workflows have to stay manual. For single-document edits, use the built-in macro recorder. For batch operations on exported assets, work with SVG files directly using shell scripts or Python. For complex, multi-step workflows that require navigating the GUI, AI desktop agents offer the most flexible and maintainable path forward. Start with the simplest tool that solves your problem, and only escalate when you hit a real wall.

Fazm is an open source macOS AI agent that can automate desktop applications like Affinity Designer through accessibility APIs. Open source on GitHub.

Related Posts