name: alfred-imessage-triage description: "[Alfred] Scan iMessage for work leads. Flag spam for manual deletion." allowed-tools: Read, Write, Edit, Bash(sqlite3:, python3:, git:, pnpm:)
Alfred iMessage Triage
Scope: Last 100 conversations. Surface work leads, flag spam.
Required Context
context/WHO_IS_MASTER.md— phone numbers, accountscontext/TEAM.md— identify work contacts vs personal
Status Definitions
ACTION_NEEDED— requires responseREPLIED— ball in their courtNOTED— FYISKIPPED— personal (hide content)NOTIFICATION— stale verification/delivery (delete)SPAM— scam/marketing (delete)
Process
1. Query iMessage Database
import sqlite3, os
from glob import glob
def load_contacts():
contacts = {}
for db in glob(os.path.expanduser("~/Library/Application Support/AddressBook/Sources/*/AddressBook-v22.abcddb")):
try:
for name, phone in sqlite3.connect(db).execute(
"SELECT COALESCE(r.ZFIRSTNAME,'') || ' ' || COALESCE(r.ZLASTNAME,''), p.ZFULLNUMBER "
"FROM ZABCDRECORD r JOIN ZABCDPHONENUMBER p ON p.ZOWNER = r.Z_PK"):
if phone: contacts[''.join(c for c in phone if c.isdigit() or c == '+')] = name.strip()
except: pass
return contacts
def extract_text(text, body):
if text: return text[:150].replace('\n', ' ')
if body and b'NSString' in body:
try: return ''.join(chr(b) for b in body.split(b'NSString')[1] if 32 <= b < 127)[:150]
except: pass
contacts = load_contacts()
conn = sqlite3.connect(os.path.expanduser('~/Library/Messages/chat.db'))
for chat_id, name, last in conn.execute(
"SELECT c.chat_identifier, c.display_name, datetime(MAX(m.date)/1000000000 + 978307200, 'unixepoch', 'localtime') "
"FROM chat c JOIN chat_message_join cmj ON c.ROWID = cmj.chat_id JOIN message m ON cmj.message_id = m.ROWID "
"GROUP BY c.ROWID ORDER BY MAX(m.date) DESC LIMIT 100"):
msg = conn.execute("SELECT text, attributedBody FROM message m JOIN chat_message_join cmj ON m.ROWID = cmj.message_id "
"JOIN chat c ON cmj.chat_id = c.ROWID WHERE c.chat_identifier = ? ORDER BY m.date DESC LIMIT 1", (chat_id,)).fetchone()
text = extract_text(msg[0], msg[1]) if msg else ''
contact = contacts.get(''.join(c for c in chat_id if c.isdigit() or c == '+'), name or '')
print(f"{chat_id}|{contact}|{last}|{text}")
2. Classify
- Spam patterns: Short codes with verification only, scam jobs ("Amazon recruitment", "McCann"), phishing, loans, "reply STOP"
- Privacy: SKIPPED = "Personal" only, no message content shown
3. Write Report
Output: outputs/YYYY-MM-DD-HHmm-imessage-triage.md (local time)
Output Template
STATUS: COMPLETE
# iMessage Triage — YYYY-MM-DD HH:mm
## Summary
- ACTION_NEEDED: X
- REPLIED: X
- NOTED: X
- SKIPPED: X
- NOTIFICATION: X
- SPAM: X
## Action Items
1. **Contact** — Summary → Action
2. ...
## Manual Deletion
**macOS 26+ blocks automated deletion.** Delete in Messages app:
1. Cmd+F → search chat ID
2. Right-click → Delete
### Notifications (stale)
- Chat ID — Preview
- ...
### Spam
- Chat ID — Preview
- ...
## Full Audit
1. **Contact** (Chat ID) — STATUS
- Notes
2. ...
Limitations
- Full Disk Access required for Terminal
- Manual deletion only (AppleScript blocked on macOS 26+)