Search and filter iMessage history from command line.
Search iMessage history with regex patterns, date ranges, and participant filters. Extract links and media files. Output text or JSON.
- Contact filtering (sender/recipient matching)
- Date range queries with relative formats
- Link extraction (YouTube, Twitter, etc.)
- File and image attachment search
- Inline terminal images
- Boolean expressions
macOS, ruby 3.4+, SQLite.
Full Disk Access must be enabled for terminal.
iTerm or Ghostty (or other kitty) for image support.
swiftc for development. (run rake build:lib)
gem install imsg-grep
imsg-grep [options] [PATTERN]
Date filtering:
-d, --since DATE- Match after date-u, --until DATE- Match before date
Participants:
-f, --from CONTACT- Match sender-t, --to CONTACT- Match recipients-w, --with CONTACT- Match sender or recipients-c, --chat [PATTERN]- Match group chats
Messages:
-M, --message PATTERN- Match message text-s, --sent- Only sent messages-r, --received- Only received messages-n, --max NUM- Limit results
Links:
-L, --links [PATTERN]- Find links-Y, --youtube- Find YouTube links-X, --twitter- Find Twitter links
Format:
-l, --one-line- Compact format-j, --json- JSON output-o, --capture [EXPR]- Extract matched parts-k, --count- Show total count
Media:
-F, --files [KIND]- Find file attachments-g, --images- Find images with preview
See --help for more.
# Basic search
imsg-grep "hello"
# From specific contact since date
imsg-grep -f Alice -d 2024-01-01 "meeting"
# YouTube links in group chats
imsg-grep -c -Y
# Extract usernames from mentions
imsg-grep -o '@(\w+)' '@\w+'
# JSON output
imsg-grep -j -f Bob -d 1w- ISO8601:
2024-12-30,2024-12-30T12:45Z - Relative:
1w(1 week),30min,3a(3am today)
Regular expressions by default. Use -q for literal matching, -i/-I for case control.