scripts/mail-refresh.sh # All accounts, wait up to 10s
scripts/mail-refresh.sh Google # Specific account only
scripts/mail-refresh.sh "" 5 # All accounts, max 5 seconds
scripts/mail-refresh.sh Google 0 # Google account, no wait
Smart sync detection:
Script monitors database message count
Returns early when sync completes (no changes for 2s)
Reports new message count: Sync complete in 2s (+3 messages)
Notes:
Mail.app must be running (script will error if not)
mail-list.sh does NOT auto-refresh — call mail-refresh.sh first if you need fresh data
Output Format
List/search returns: ID | ReadStatus | Date | Sender | Subject
● = unread, blank = read
Gmail Mailboxes
⚠️ Gmail special folders need [Gmail]/ prefix:
Shows as
Use
Spam
[Gmail]/Spam
Sent Mail
[Gmail]/Sent Mail
All Mail
[Gmail]/All Mail
Trash
[Gmail]/Trash
Custom labels work without prefix.
Fast Search (SQLite)
✨ Now safe even if Mail.app is running — copies database to temp file first.
scripts/mail-fast-search.sh "query" [limit] # ~50ms vs minutes
Previously required Mail.app to be quit. Now works anytime by copying the database to a temp file before querying.
Performance Notes
Speed by operation:
Operation
Speed
Notes
mail-fast-search.sh
~50ms
SQLite query, fastest
mail-accounts.sh
<1s
Simple AppleScript
mail-list.sh
1-3s
AppleScript, direct mailbox access
mail-send.sh
1-2s
Creates and sends message
mail-read.sh
~2s
Position-optimized lookup
mail-delete.sh
~0.5s
Position-optimized lookup
mail-mark-*.sh
~1.5s
Position-optimized lookup
Optimization technique:
SQLite provides account UUID and approximate message position. AppleScript jumps directly to that position instead of iterating from the start.
Batch operations supported:
mail-read.sh 123 456 789 - Read multiple (separator between each)
mail-delete.sh 123 456 789 - Delete multiple
mail-mark-read.sh 123 456 - Mark multiple as read
mail-mark-unread.sh 123 456 - Mark multiple as unread
⚠️ No auto-refresh: Scripts read cached data. Call mail-refresh.sh first if you need latest emails.