AgentScripts

March 30, 2026 ยท View on GitHub

Dynamic Swift scripts for the Agent! macOS app. These scripts compile at runtime as dynamic libraries (.dylib) and are loaded into the app via dlopen.

How It Works

  1. On first launch, the Agent! app clones this repo to ~/Documents/AgentScript/agents/
  2. Each script is compiled individually via swift build as a dynamic library
  3. The app loads the compiled .dylib and calls the script_main() entry point
  4. Scripts can import bridges from AgentEventBridges to control macOS apps via Apple Events

Writing a Script

Every script must export a C-callable script_main function:

import Foundation

@_cdecl("script_main")
public func scriptMain() -> Int32 {
    print("Hello from my script!")
    return 0  // exit code
}

Importing Bridges

To control macOS apps, import the corresponding bridge:

import Foundation
import ScriptingBridge
import MusicBridge

@_cdecl("script_main")
public func scriptMain() -> Int32 {
    guard let app = SBApplication(bundleIdentifier: "com.apple.Music") else { return 1 }
    // Use the Music scripting bridge...
    return 0
}

Input / Output

Scripts receive input via the AGENT_SCRIPT_ARGS environment variable or JSON files:

  • Input: ~/Documents/AgentScript/json/<ScriptName>_input.json
  • Output: ~/Documents/AgentScript/json/<ScriptName>_output.json

Output Directories

Scripts can write files to these organized folders under ~/Documents/AgentScript/:

FolderPurpose
json/JSON input/output
photos/Captured photos
images/Generated images
screenshots/Screen captures
html/HTML output
applescript/Saved AppleScripts
javascript/Saved JXA scripts
logs/Log files
recordings/Recordings

Included Scripts

ScriptDescription
HelloTest script for verifying setup
SystemInfoSystem information report
RunningAppsList running applications
NowPlayingCurrent Music track info
CheckMailCheck Mail.app for new messages
ListNotesList notes from Notes.app
ListRemindersList reminders from Reminders.app
TodayEventsToday's Calendar events
SafariSearchPerform a Safari search
SendMessageSend an iMessage
CapturePhotoCapture a photo from the camera
GenerateBridgeGenerate a new scripting bridge from an app's SDEF

Managing Scripts

The Agent! app provides tools to create, update, delete, and run scripts:

  • create_agent_script - Create a new script
  • update_agent_script - Modify an existing script
  • delete_agent_script - Remove a script
  • run_agent_script - Compile and execute a script
  • list_agent_scripts - List all available scripts

License

MIT