An Osaurus plugin for interacting with macOS Messages.app. Send and read iMessages programmatically.
Grant permission in:
- System Settings > Privacy & Security > Automation
Add the application using this plugin (e.g., Osaurus, or your terminal if running from CLI) and enable access to Messages.
Grant permission in:
- System Settings > Privacy & Security > Full Disk Access
Add the application using this plugin. This is required to access the Messages database at ~/Library/Messages/chat.db.
Send an iMessage to a phone number. Uses AppleScript to interact with Messages.app directly.
Parameters:
phoneNumber(required): The recipient's phone number (e.g.,+1234567890or1234567890)message(required): The message content to send
Example:
{
"phoneNumber": "+15551234567",
"message": "Hello from Osaurus!"
}Response:
{
"success": true,
"message": "Message sent to +15551234567"
}Read message history from a specific contact. Queries the Messages database directly using the native SQLite C API.
Parameters:
phoneNumber(required): The contact's phone number to read messages fromlimit(optional): Maximum number of messages to return (default: 10, max: 50)
Example:
{
"phoneNumber": "+15551234567",
"limit": 5
}Response:
[
{
"content": "Hey, how are you?",
"date": "2024-01-15 14:30:00",
"sender": "+15551234567",
"isFromMe": false,
"attachments": null
},
{
"content": "Check out this photo",
"date": "2024-01-15 14:32:00",
"sender": "+15551234567",
"isFromMe": true,
"attachments": ["photo.jpg"]
}
]Get all unread messages from all contacts. Queries the Messages database directly using the native SQLite C API.
Parameters:
limit(optional): Maximum number of messages to return (default: 10, max: 50)
Example:
{
"limit": 10
}Response:
[
{
"content": "Are you coming to the meeting?",
"date": "2024-01-15 15:00:00",
"sender": "+15559876543",
"isFromMe": false,
"attachments": null
}
]All message-reading tools return messages in this format:
| Field | Type | Description |
|---|---|---|
content |
string |
The message text, [Rich text message] for formatted messages, or [Attachment] for media-only messages |
date |
string |
Date/time the message was sent (local time) |
sender |
string |
Phone number or email of the sender (Me or Unknown when unavailable) |
isFromMe |
boolean |
Whether you sent this message |
attachments |
string[] |
List of attachment filenames (e.g., ["photo.jpg", "document.pdf"]), or null if none |
- Sending messages: Uses
NSAppleScriptto interact with Messages.app via AppleScript. Requires Automation permissions. - Reading messages: Uses the native SQLite C API (
import SQLite3) to query~/Library/Messages/chat.dbdirectly in read-only mode. Requires Full Disk Access. All queries use parameterized bindings to prevent injection.
-
Build:
swift build -c release cp .build/release/libosaurus-messages.dylib ./libosaurus-messages.dylib
-
Install locally:
osaurus tools install .
codesign --force --options runtime --timestamp \
--sign "Developer ID Application: Your Name (TEAMID)" \
.build/release/libosaurus-messages.dylibosaurus tools package osaurus.messages 0.1.0This creates osaurus.messages-0.1.0.zip for distribution.
This error means the application doesn't have Full Disk Access. To fix:
- Open System Settings > Privacy & Security > Full Disk Access
- Click the lock icon to make changes
- Add the application (Terminal.app, iTerm.app, or Osaurus)
- Restart the application
This typically means:
- Messages.app is not set up or logged in
- The phone number format is incorrect
- Automation permissions haven't been granted
Ensure you've granted Automation permissions and that Messages.app is properly configured with your iMessage account.
Some messages use rich formatting (links, mentions, reactions) and store text in a binary format (attributedBody) that cannot be directly read as plain text. The actual message content exists but is displayed with this placeholder.
These are media-only messages (photos, videos, audio) with no accompanying text. The attachment filenames are returned in the attachments field when available.
- Inspired by apple-mcp by supermemoryai