Skip to content

Machine API Reference

The context.machine API is available to plugins that declare machineCapabilities in their manifest. It allows plugins to interact with the user's connected machine through PIE Connect.

context.machine.isOnline()

Check if the user has at least one online machine.

Returns: Promise<boolean>

javascript
const online = await context.machine.isOnline();

context.machine.list()

List all connected machines for the current user.

Returns: Promise<Array<{ machineId: string, capabilities: string[], connectedAt: number }>>

javascript
const machines = await context.machine.list();

context.machine.execute(capability, params)

Execute a command on the user's machine. The plugin's manifest must declare the capability, and the user must have approved it at install time.

Parameters:

  • capability (string) — The capability to execute (e.g., "machine.info")
  • params (object) — Parameters for the capability

Returns: Promise<any>

javascript
const result = await context.machine.execute('machine.info', {});

context.machine.upload(macPath)

Convenience method to upload a file from the Mac to PIE cloud storage. Equivalent to execute('file.transfer', { action: 'upload', path: macPath }).

Parameters:

  • macPath (string) — File path on the Mac (supports ~ for home directory)

Returns: Promise<{ action, fileId, url, size, filename, mimeType, sourcePath }>

javascript
const uploaded = await context.machine.upload('~/Documents/report.pdf');
console.log(uploaded.fileId, uploaded.url); // file ID and view URL

context.machine.download(urlOrGcsPath, macSavePath)

Convenience method to download a file from the cloud to the Mac. Equivalent to execute('file.transfer', { action: 'download', ... }).

Parameters:

  • urlOrGcsPath (string) — A URL to download from, or a GCS path from a previous upload
  • macSavePath (string) — Path on the Mac to save the file

Returns: Promise<{ action, savedTo, size, filename }>

javascript
await context.machine.download('https://example.com/file.pdf', '~/Downloads/file.pdf');

Capabilities Reference

machine.info

Read basic machine information.

Risk: Low Platforms: macOS, Linux, Windows Parameters: None Returns:

json
{
  "hostname": "Jakes-MacBook-Pro",
  "platform": "darwin",
  "arch": "arm64",
  "osType": "Darwin",
  "osRelease": "24.0.0",
  "osVersion": "Darwin Kernel Version 24.0.0",
  "uptime": 123456,
  "totalMemory": 17179869184,
  "freeMemory": 8589934592,
  "cpus": 10,
  "nodeVersion": "v22.0.0",
  "homeDir": "/Users/jake",
  "username": "jake"
}

clipboard.read

Read the current clipboard contents.

Risk: Medium Platforms: macOS, Linux, Windows Parameters: None Returns:

json
{
  "content": "Hello, world!",
  "length": 13
}

clipboard.write

Write text to the system clipboard.

Risk: Medium Platforms: macOS, Linux, Windows Parameters:

NameTypeDescription
textstringThe text to write to the clipboard (required)

Returns:

json
{
  "written": true,
  "length": 13
}

notifications.send

Send a desktop notification.

Risk: Low Platforms: macOS, Linux, Windows Parameters:

NameTypeDescription
titlestringNotification title (default: "PIE")
messagestringNotification body (default: "Notification from PIE")

Returns:

json
{
  "sent": true,
  "title": "PIE",
  "message": "Hello from PIE!"
}

messages.read

Read iMessages from the Mac's Messages database. macOS only. Requires Full Disk Access permission.

Risk: High Parameters:

NameTypeDescription
limitnumberMax messages to return (1-100, default: 5)
contactstringFilter by contact (partial match)
afterstringISO date string — only messages after this date

Returns:

json
{
  "messages": [
    {
      "text": "Hey, are you free tonight?",
      "fromMe": false,
      "date": "2025-01-15 14:30:00",
      "sender": "+15551234567"
    }
  ],
  "count": 1
}

screenshot.capture

Capture a screenshot of the Mac screen.

Risk: High Platforms: macOS Parameters:

NameTypeDescription
qualitynumberJPEG quality (1-100, default: 60)
maxWidthnumberMax image width in pixels (default: 1280)

Returns:

json
{
  "image": "data:image/jpeg;base64,...",
  "width": 1280,
  "height": 800
}

desktop.control

Control mouse and keyboard on the Mac. macOS only. Requires Accessibility permission.

Risk: Critical Parameters:

NameTypeDescription
actionstringRequired. One of: click, double_click, right_click, move, drag, scroll, type, press_key, info, open_app
x, ynumberCoordinates for click/move/scroll actions
startX, startY, endX, endYnumberCoordinates for drag action
deltaYnumberScroll amount for scroll action
textstringText for type action
keystringKey name or combo for press_key (e.g., "return", "cmd+c")
modifiersstring[]Optional modifiers for press_key (["cmd", "shift"])
namestringApp name for open_app action

Returns: Object with action, success, and action-specific fields.

shell.run

Execute shell commands on the machine.

Risk: Critical Platforms: macOS, Linux, Windows Parameters:

NameTypeDescription
commandstringThe shell command to execute (required)
cwdstringWorking directory (default: user home)
timeoutnumberTimeout in ms (default: 30000, max: 120000)

Returns:

json
{
  "exitCode": 0,
  "stdout": "hello world\n",
  "stderr": "",
  "command": "echo hello world",
  "cwd": "/Users/jake"
}

filesystem

Read, write, list, search, move, copy, and delete files.

Risk: High Platforms: macOS, Linux, Windows Parameters:

NameTypeDescription
actionstringRequired. One of: read, write, list, search, move, copy, delete, stat

Action: read — Read a file's contents (max 5MB)

NameTypeDescription
pathstringFile path (supports ~ for home dir)
encodingstringEncoding (default: utf-8)

Action: write — Write or append to a file

NameTypeDescription
pathstringFile path
contentstringContent to write
appendbooleanAppend instead of overwrite (default: false)

Action: list — List directory contents

NameTypeDescription
pathstringDirectory path
recursivebooleanRecurse into subdirectories (default: false)
globstringFilter by name pattern
showHiddenbooleanInclude hidden files (default: false)

Action: search — Search file contents

NameTypeDescription
pathstringDirectory to search in
patternstringSearch pattern
maxResultsnumberMax results (default: 200)

Action: move — Move or rename a file

NameTypeDescription
sourcestringSource path
destinationstringDestination path

Action: copy — Copy a file or directory

NameTypeDescription
sourcestringSource path
destinationstringDestination path

Action: delete — Delete a file or directory

NameTypeDescription
pathstringPath to delete
recursivebooleanRequired for directories (default: false)

Action: stat — Get file metadata

NameTypeDescription
pathstringFile or directory path

Returns (stat example):

json
{
  "action": "stat",
  "path": "/Users/jake",
  "exists": true,
  "type": "directory",
  "size": 1024,
  "sizeHuman": "1.0KB",
  "created": "2024-01-01T00:00:00.000Z",
  "modified": "2025-03-14T12:00:00.000Z",
  "permissions": "755"
}

apps.automate

Automate macOS applications via scoped AppleScript. The script is always executed inside a tell application block for the specified app. Timeout is 30 seconds.

Risk: High Platforms: macOS Parameters:

NameTypeDescription
appstringApplication name (e.g., "Spotify", "Finder", "Calendar")
scriptstringAppleScript commands to run inside tell application block

Safety: Scripts cannot contain the following patterns (use shell.run or filesystem instead): do shell script, run script, system attribute, path to startup disk, do script, POSIX file, call method, store script, load script, scripting additions.

Returns:

json
{
  "app": "Spotify",
  "output": "Playing",
  "success": true,
  "dictionary": "Commands: play — Play the current track; pause — Pause playback; ...\nClasses: track [props: name, artist, album, duration, ...]"
}

The dictionary field contains a condensed summary of the app's AppleScript scripting dictionary (sdef), automatically fetched in parallel with script execution and cached. It lists available commands and classes with their properties. This is especially useful on errors — the dictionary shows what commands are actually available so the script can be corrected.

Examples:

javascript
// Play Spotify
await context.machine.execute('apps.automate', {
  app: 'Spotify',
  script: 'play'
});

// Get current track
await context.machine.execute('apps.automate', {
  app: 'Spotify',
  script: 'get name of current track'
});

// Set volume
await context.machine.execute('apps.automate', {
  app: 'Spotify',
  script: 'set sound volume to 50'
});

// Create a reminder
await context.machine.execute('apps.automate', {
  app: 'Reminders',
  script: 'make new reminder with properties {name:"Buy groceries", body:"Milk, eggs, bread"}'
});

// Open a URL in Safari
await context.machine.execute('apps.automate', {
  app: 'Safari',
  script: 'open location "https://example.com"'
});

browser.data

Read browser tabs, history, and bookmarks from Safari and Chrome.

Risk: High Platforms: macOS Parameters:

NameTypeDescription
actionstringRequired. One of: tabs, history, bookmarks
browserstring"safari" or "chrome" (default: "safari")
limitnumberMax results (default: 50, max: 500)

Returns (tabs example):

json
{
  "action": "tabs",
  "browser": "safari",
  "tabs": [
    { "title": "GitHub", "url": "https://github.com", "windowIndex": 0 },
    { "title": "Google", "url": "https://google.com", "windowIndex": 0 }
  ],
  "count": 2
}

Returns (history example):

json
{
  "action": "history",
  "browser": "safari",
  "history": [
    { "url": "https://github.com", "title": "GitHub", "visit_date": "2025-03-14 10:30:00" }
  ],
  "count": 1,
  "limit": 50
}

contacts.read

Read contacts from macOS Contacts.

Risk: High Platforms: macOS Parameters:

NameTypeDescription
searchstringFilter by name (partial match)
limitnumberMax contacts to return (default: 50, max: 500)
fieldsstring[]Fields to include: name, email, phone, company, address, birthday, notes (default: ["name", "email", "phone"])

Returns:

json
{
  "contacts": [
    {
      "firstName": "Jane",
      "lastName": "Doe",
      "name": "Jane Doe",
      "emails": [{ "label": "work", "value": "[email protected]" }],
      "phones": [{ "label": "mobile", "value": "+15551234567" }]
    }
  ],
  "count": 1,
  "total": 342,
  "search": null,
  "fields": ["name", "email", "phone"]
}

calendar.read

Read events from macOS Calendar.

Risk: High Platforms: macOS Parameters:

NameTypeDescription
fromstringStart date (ISO format, default: today)
tostringEnd date (ISO format, default: 7 days from start)
calendarstringFilter by calendar name
limitnumberMax events to return (default: 50, max: 500)

Returns:

json
{
  "events": [
    {
      "summary": "Team Standup",
      "calendar": "Work",
      "startDate": "2025-03-14T09:00:00.000Z",
      "endDate": "2025-03-14T09:30:00.000Z",
      "location": "Zoom",
      "description": null,
      "allDay": false
    }
  ],
  "count": 1,
  "calendarCount": 4,
  "from": "2025-03-14T00:00:00.000Z",
  "to": "2025-03-21T00:00:00.000Z"
}

system.control

Read and control system settings.

Risk: Medium Platforms: macOS Parameters:

NameTypeDescription
actionstringRequired. One of: volume, set_volume, dark_mode, set_dark_mode, wifi_status, bluetooth_devices, battery, running_apps, disk_usage, network_info
levelnumberVolume level (0-100) for set_volume
enabledbooleanDark mode state for set_dark_mode

Returns (volume example):

json
{
  "action": "volume",
  "outputVolume": 75,
  "inputVolume": 80,
  "outputMuted": false
}

Returns (battery example):

json
{
  "action": "battery",
  "percent": 87,
  "powerSource": "AC Power",
  "status": "charging"
}

Returns (running_apps example):

json
{
  "action": "running_apps",
  "apps": [
    { "name": "Spotify", "bundleId": "com.spotify.client", "pid": 1234 },
    { "name": "Safari", "bundleId": "com.apple.Safari", "pid": 5678 }
  ],
  "count": 15
}

Returns (network_info example):

json
{
  "action": "network_info",
  "interfaces": [
    { "name": "en0", "ipv4": "192.168.1.100" }
  ],
  "publicIp": "203.0.113.1"
}

file.transfer

Upload files from the Mac to PIE cloud storage, or download files from the cloud to the Mac. Supports files up to 100MB. Uploaded files appear in the user's PIE Files and are associated with the calling plugin.

Risk: High Platforms: macOS, Linux, Windows Parameters:

NameTypeDescription
actionstringRequired. "upload" or "download"

Action: upload — Upload a file from Mac to cloud

NameTypeDescription
pathstringFile path on the Mac (supports ~ for home dir)

Returns (upload):

json
{
  "action": "upload",
  "fileId": "be3df226-9f8a-4ebe-9400-7cc238023bf3",
  "url": "/api/files/be3df226-.../view",
  "size": 76292,
  "filename": "report.pdf",
  "mimeType": "application/pdf",
  "sourcePath": "/Users/jake/Documents/report.pdf"
}

Action: download — Download a file from cloud to Mac

NameTypeDescription
urlstringURL to download from
gcsPathstringGCS path from a previous upload (alternative to url)
savePathstringPath on Mac to save the file (required)

Returns (download):

json
{
  "action": "download",
  "savedTo": "/Users/jake/Downloads/report.pdf",
  "size": 76292,
  "filename": "report.pdf"
}

Convenience methods: Use context.machine.upload(path) and context.machine.download(url, savePath) instead of calling execute directly.


Error Codes

ErrorDescription
MACHINE_OFFLINENo machine is currently connected
MACHINE_TIMEOUTMachine didn't respond within 60 seconds
Capability not found or is disabledThe requested capability is not available on the machine
Plugin does not declare machine capabilityThe plugin's manifest doesn't include this capability
User has not approved machine capabilityThe user hasn't approved this capability for the plugin

Built with VitePress