Introduction
iMessage is the native messaging service in the Apple ecosystem, featuring end-to-end encryption and rich message formats. OpenClaw supports connecting to iMessage through AppleScript bridging on macOS, allowing you to chat with AI directly within iMessage. This article covers the configuration process and important considerations in detail.
Key Prerequisites
Before you begin, please be aware of the following critical requirements:
| Requirement | Details |
|---|---|
| Operating System | macOS only (iMessage bridging depends on Messages.app) |
| macOS Version | macOS 13 Ventura or later |
| Apple ID | Must be signed in to iMessage with an Apple ID |
| Runtime | OpenClaw must run natively on macOS (not in Docker) |
| Accessibility | Terminal/Node.js must be granted Accessibility permissions |
Note: iMessage bridging is only supported on macOS. If you are using
Linux or Windows, please consider other messaging channels (such as
WhatsApp, Telegram, etc.).
How It Works
OpenClaw's iMessage integration uses the following architecture:
User sends an iMessage
↓
macOS Messages.app receives the message
↓
OpenClaw reads the new message via AppleScript
↓
Message is sent to an AI model for processing
↓
AI generates a reply
↓
OpenClaw sends the iMessage reply via AppleScript
↓
User receives the reply
The core mechanism leverages macOS's AppleScript interface to interact with Messages.app. OpenClaw periodically polls the Messages.app database to detect new messages, then sends replies through AppleScript commands.
Step 1: System Permission Configuration
1.1 Enable Accessibility Permissions
OpenClaw needs Accessibility permissions to control Messages.app:
- Open System Settings > Privacy & Security > Accessibility
- Click the lock icon and enter your admin password
- Click the + button and add your Terminal app (Terminal.app or iTerm)
- If you run OpenClaw via a globally installed Node.js, you also need to add Node.js:
# Find the Node.js path
which node
# Typically /usr/local/bin/node or /opt/homebrew/bin/node
1.2 Grant Automation Permissions
On the first run, macOS will display a dialog asking whether to allow the terminal to control Messages.app. Click Allow.
If you missed the prompt, you can set it manually:
System Settings > Privacy & Security > Automation > Find the terminal app > Check Messages
1.3 Ensure Messages.app Is Signed In
- Open Messages.app
- Make sure you are signed in with your Apple ID
- Verify that you can send and receive iMessages normally
# Verify that Messages.app is accessible via AppleScript
osascript -e 'tell application "Messages" to get name'
If it returns "Messages," the permissions are configured correctly.
Step 2: Configure OpenClaw
2.1 Configuration File
Edit ~/.config/openclaw/openclaw.json5:
{
channels: {
imessage: {
enabled: true,
// Polling interval (seconds) — how often to check for new messages
pollInterval: 3,
// Messages.app database path (usually no modification needed)
dbPath: "~/Library/Messages/chat.db",
// Security configuration
security: {
// Allowed contacts list (empty array means everyone is allowed)
allowedContacts: [],
// Or filter by phone number/email
allowedIdentifiers: [
"+8613800138000",
"[email protected]"
],
// Whether to allow group chat messages
groupChatEnabled: false,
// Whether to allow unknown contacts
allowUnknown: false
},
// Trigger configuration
trigger: {
// Whether to auto-reply to all private messages
autoReply: true,
// Trigger keywords (if you don't want to auto-reply to everything)
keywords: [],
// Group chat trigger method
groupTrigger: "keyword",
groupKeywords: ["@AI", "/ask"]
},
// Reply configuration
reply: {
// Maximum message length
maxLength: 10000,
// Whether to send long code blocks as attachments
codeAsAttachment: false,
// Send delay (milliseconds) to simulate typing
sendDelay: 500
}
}
}
}
2.2 Minimal Configuration
For a quick test, use this minimal configuration:
{
channels: {
imessage: {
enabled: true,
security: {
// Only allow specific contacts (strongly recommended)
allowedIdentifiers: ["+8613800138000"]
}
}
}
}
2.3 Restart the Service
openclaw restart
# View iMessage channel logs
openclaw logs -f --component channel:imessage
Logs upon successful startup:
[INFO] [channel:imessage] iMessage bridge started
[INFO] [channel:imessage] Messages.app connection OK
[INFO] [channel:imessage] Polling interval: 3 seconds
[INFO] [channel:imessage] Allowed contacts: 1
[INFO] [channel:imessage] Waiting for new messages...
Step 3: Test the Connection
3.1 Send a Test Message
From another device (iPhone or another Mac), send an iMessage to the Apple ID running OpenClaw:
Hello, this is a test message
3.2 Check the Logs
openclaw logs -f --component channel:imessage
You should see logs similar to:
[INFO] [channel:imessage] New message received: from="+8613800138000", text="Hello, this is a test message"
[INFO] [channel:imessage] Sending to model for processing: claude
[INFO] [channel:imessage] Model reply complete (1.2s)
[INFO] [channel:imessage] Reply sent to: +8613800138000
Security Considerations
iMessage integration involves your personal messages, so security measures are critical:
Always Configure a Contact Whitelist
{
channels: {
imessage: {
security: {
// Strongly recommended: set a whitelist; otherwise any message will trigger a reply
allowedIdentifiers: [
"+8613800138000",
"[email protected]"
],
allowUnknown: false
}
}
}
}
Database Access Security
OpenClaw needs to read ~/Library/Messages/chat.db, which is the local database for Messages.app. Keep the following in mind:
- Ensure the macOS user account running OpenClaw is secure
- Enable FileVault full-disk encryption
- Set a strong password and enable auto-lock
Privacy Considerations
iMessage conversation content will be sent to the AI model API for processing.
Make sure you understand the data privacy policy of the model you are using.
For sensitive information, consider using a local model (such as Ollama).
Supported Message Types
| Message Type | Receive | Send | Notes |
|---|---|---|---|
| Plain text | Supported | Supported | Fully supported |
| Image | Supported | Not supported | Requires a multimodal model for recognition |
| Link | Supported | Supported | Automatic URL preview extraction |
| Attachment | Partial | Not supported | Only text-based attachments are supported |
| Tapback reactions | Not supported | Not supported | Ignored |
| Memoji | Not supported | Not supported | Ignored |
Persistent Running Configuration
To keep the iMessage bridge running continuously, it is recommended to use macOS's launchd to manage the OpenClaw process:
Create a launchd Configuration
cat > ~/Library/LaunchAgents/com.openclaw.agent.plist << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.openclaw.agent</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/openclaw</string>
<string>up</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/openclaw.stdout.log</string>
<key>StandardErrorPath</key>
<string>/tmp/openclaw.stderr.log</string>
</dict>
</plist>
EOF
Load the Configuration
launchctl load ~/Library/LaunchAgents/com.openclaw.agent.plist
Manage the Service
# Stop the service
launchctl stop com.openclaw.agent
# Start the service
launchctl start com.openclaw.agent
# Unload the service
launchctl unload ~/Library/LaunchAgents/com.openclaw.agent.plist
Known Limitations
- macOS only — This is the most significant limitation; it cannot be used on other operating systems
- Requires a graphical interface — Messages.app needs a graphical environment; pure SSH sessions are not supported
- Polling mode — New messages are detected by polling the database, resulting in a few seconds of delay
- No rich media in replies — Replies are limited to plain text; images and files cannot be sent
- Single instance only — Only one iMessage bridge instance can run on a single Mac
- macOS update risk — System updates may affect AppleScript interface compatibility
Troubleshooting
Messages.app Is Not Accessible
# Reset AppleEvents permissions
tccutil reset AppleEvents
# Restart OpenClaw and wait for the permission prompt
openclaw restart
Database Lock Error
# If you see a "database is locked" error
# Close other applications that may be accessing chat.db
# Or increase the polling interval
openclaw config set channels.imessage.pollInterval 5
Message Sending Failure
# Test whether AppleScript can send a message
osascript -e 'tell application "Messages"
set targetService to 1st account whose service type = iMessage
set targetBuddy to participant "+8613800138000" of targetService
send "Test message" to targetBuddy
end tell'
Summary
iMessage integration lets you seamlessly use an AI assistant within the Apple ecosystem. Key takeaways:
- macOS only — Requires Messages.app and Accessibility permissions
- Strongly recommended to set a contact whitelist for privacy protection
- Use launchd for auto-start on boot and process supervision
- Be aware of the known limitations, especially polling delay and lack of rich media support
- For sensitive conversations, consider using a local model such as Ollama