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.
- On first launch, the Agent! app clones this repo to
~/Documents/AgentScript/agents/ - Each script is compiled individually via
swift buildas a dynamic library - The app loads the compiled
.dyliband calls thescript_main()entry point - Scripts can import bridges from AgentEventBridges to control macOS apps via Apple Events
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
}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
}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
Scripts can write files to these organized folders under ~/Documents/AgentScript/:
| Folder | Purpose |
|---|---|
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 |
| Script | Description |
|---|---|
| Hello | Test script for verifying setup |
| SystemInfo | System information report |
| RunningApps | List running applications |
| NowPlaying | Current Music track info |
| CheckMail | Check Mail.app for new messages |
| ListNotes | List notes from Notes.app |
| ListReminders | List reminders from Reminders.app |
| TodayEvents | Today's Calendar events |
| SafariSearch | Perform a Safari search |
| SendMessage | Send an iMessage |
| CapturePhoto | Capture a photo from the camera |
| GenerateBridge | Generate a new scripting bridge from an app's SDEF |
The Agent! app provides tools to create, update, delete, and run scripts:
create_agent_script- Create a new scriptupdate_agent_script- Modify an existing scriptdelete_agent_script- Remove a scriptrun_agent_script- Compile and execute a scriptlist_agent_scripts- List all available scripts
MIT