Custom Actions Reference

Pipeline provides custom actions via the pipeline object. These extend Figma's capabilities with user interaction, AI requests, file downloads, and more.


pipeline.getUserInput(prompt, defaultValue?)

Show a modal dialog and wait for user input.

Opens an input dialog with a text field. Execution pauses until the user submits or cancels.

Parameters

ParameterTypeRequiredDescription
promptstringYesText shown above the input field
defaultValuestringNoPre-filled value in the input field

Returns

Promise<string> — The user's input, or defaultValue if cancelled

Examples

Ask for prefix

const prefix = await pipeline.getUserInput("Enter prefix:", "icon-");

for (const node of figma.currentPage.selection) {
  node.name = prefix + node.name;
}

console.log(`Added prefix "${prefix}" to ${figma.currentPage.selection.length} layers`);

Multi-step input

const width = await pipeline.getUserInput("Frame width:", "1920");
const height = await pipeline.getUserInput("Frame height:", "1080");

const frame = figma.createFrame();
frame.resize(parseInt(width), parseInt(height));
frame.name = `Frame ${width}x${height}`;

pipeline.aiRequest(prompt)

Make an AI request from your code.

Sends a prompt to AI and returns the response. Useful for content generation, analysis, translations, and intelligent automation.

Parameters

ParameterTypeRequiredDescription
promptstringYesThe prompt to send to AI

Returns

Promise<string> — The AI response text

Examples

Generate placeholder text

const topic = await pipeline.getUserInput("Topic for placeholder text:", "Technology");
const text = await pipeline.aiRequest(`Write 2-3 sentences about ${topic} for a website hero section.`);

const textNode = figma.createText();
await figma.loadFontAsync({ family: "Inter", style: "Regular" });
textNode.characters = text;

Translate content

const targetLang = await pipeline.getUserInput("Translate to language:", "Spanish");

for (const node of figma.currentPage.selection) {
  if (node.type === 'TEXT') {
    const translated = await pipeline.aiRequest(
      `Translate to ${targetLang}: "${node.characters}"`
    );

    await figma.loadFontAsync(node.fontName as FontName);
    node.characters = translated;
  }
}

Analyze design

const colors = figma.currentPage.selection
  .filter(n => 'fills' in n)
  .flatMap(n => n.fills)
  .filter(f => f.type === 'SOLID')
  .map(f => f.color);

const analysis = await pipeline.aiRequest(
  `Analyze this color palette for accessibility and harmony: ${JSON.stringify(colors)}`
);

console.log(analysis);

pipeline.downloadFile(data, filename, mimeType?)

Download a file to the user's computer.

Triggers a browser download with the provided data. Works with any binary data — images, SVGs, JSON, CSV, etc.

Parameters

ParameterTypeRequiredDescription
dataUint8ArrayYesBinary data to download
filenamestringYesName for the downloaded file
mimeTypestringNoMIME type. Default: 'application/octet-stream'

Returns

Promise<void>

Common MIME Types

TypeMIME
SVG'image/svg+xml'
PNG'image/png'
JPG'image/jpeg'
PDF'application/pdf'
JSON'application/json'
CSV'text/csv'
Plain text'text/plain'

Examples

Export as SVG

for (const node of figma.currentPage.selection) {
  if ('exportAsync' in node) {
    const svg = await node.exportAsync({ format: 'SVG' });
    await pipeline.downloadFile(svg, `${node.name}.svg`, 'image/svg+xml');
  }
}

Export as PNG with scale

const scale = await pipeline.getUserInput("Export scale (1-4):", "2");

for (const node of figma.currentPage.selection) {
  if ('exportAsync' in node) {
    const png = await node.exportAsync({
      format: 'PNG',
      constraint: { type: 'SCALE', value: parseInt(scale) }
    });
    await pipeline.downloadFile(png, `${node.name}@${scale}x.png`, 'image/png');
  }
}

Export data as JSON

const data = figma.currentPage.selection.map(node => ({
  name: node.name,
  type: node.type,
  x: node.x,
  y: node.y,
  width: 'width' in node ? node.width : null,
  height: 'height' in node ? node.height : null,
}));

const json = new TextEncoder().encode(JSON.stringify(data, null, 2));
await pipeline.downloadFile(json, 'selection-data.json', 'application/json');

Export as CSV

const rows = [['Name', 'Type', 'Width', 'Height']];

for (const node of figma.currentPage.selection) {
  rows.push([
    node.name,
    node.type,
    'width' in node ? String(node.width) : '',
    'height' in node ? String(node.height) : '',
  ]);
}

const csv = rows.map(row => row.join(',')).join('\n');
const data = new TextEncoder().encode(csv);
await pipeline.downloadFile(data, 'layers.csv', 'text/csv');

pipeline.sleep(ms)

Pause execution for a specified time.

Async delay that respects cancellation. If the user clicks Stop during sleep, execution terminates gracefully.

Parameters

ParameterTypeRequiredDescription
msnumberYesMilliseconds to wait

Returns

Promise<void>

Examples

Animation delay

for (let i = 0; i < 10; i++) {
  node.x += 10;
  console.log(`Step ${i + 1}`);
  await pipeline.sleep(100); // 100ms between steps
}

Rate limiting API calls

for (const node of figma.currentPage.selection) {
  if (node.type === 'TEXT') {
    const translated = await pipeline.aiRequest(`Translate: ${node.characters}`);
    node.characters = translated;
    await pipeline.sleep(500); // Wait 500ms between API calls
  }
}

Note: For complete Figma API documentation, see the Figma Plugin API Reference.