Skip to content

Fix Contacts: read iCloud-source DB, support full-name search - #1

Open
bfeeny wants to merge 1 commit into
AaronRoeF:mainfrom
bfeeny:fix-icloud-contacts-search
Open

Fix Contacts: read iCloud-source DB, support full-name search#1
bfeeny wants to merge 1 commit into
AaronRoeF:mainfrom
bfeeny:fix-icloud-contacts-search

Conversation

@bfeeny

@bfeeny bfeeny commented Apr 26, 2026

Copy link
Copy Markdown

Two related fixes for Apple Contacts on macOS where contacts are stored in iCloud.

1. resolveContactsDB() only reads the top-level AddressBook-v22.abcddb

The top-level file is the "On My Mac" store and is empty for users whose contacts are synced via iCloud. iCloud-synced contacts live in per-source databases under:

~/Library/Application Support/AddressBook/Sources/<UUID>/AddressBook-v22.abcddb

The previous code returned an empty result set with no error, since the top-level file exists but contains no records. Net effect for iCloud users: every Contacts tool returned [] or total_contacts: 0.

This patch scans the AddressBook tree (top-level + every Sources/<UUID>/) and selects the largest .abcddb as the contacts DB. For typical iCloud-only users this picks the right DB on first try.

Caveat: users with multiple active sources (iCloud + CardDAV + Exchange, etc.) will only see contacts from the largest DB. Full multi-source support would require querying every DB and unioning/deduping; happy to follow up with that if there's interest.

2. Search SQL doesn't match across first_name + last_name

Each LIKE clause matches a single field independently, so a query like "Julie Thompson" misses contacts whose first name is "Julie" and last name is "Thompson". Added an additional clause matching against the concatenated full name:

OR (COALESCE(r.ZFIRSTNAME, '') || ' ' || COALESCE(r.ZLASTNAME, '')) LIKE ?

Testing

Tested on macOS Sonoma with a ~2,300-contact iCloud library:

  • Before: apple_contacts_stats returned total_contacts: 0; all searches returned [].
  • After: stats reports the real count; apple_contacts_search "Julie Thompson" returns the right record; single-token searches continue to work.

The startup log line Using contacts DB: <path> (<size> bytes) makes it easy to verify which DB was selected.

Two related fixes for Apple Contacts on iCloud-using Macs.

1. resolveContactsDB() only read the top-level AddressBook-v22.abcddb,
   which is the "On My Mac" store and is empty for users whose contacts
   are synced via iCloud. iCloud contacts live in per-source databases
   under AddressBook/Sources/<UUID>/AddressBook-v22.abcddb. The previous
   code returned 0 results with no error, since the top-level file
   exists but contains no records. This patch scans the AddressBook
   tree (top-level + every Sources/<UUID>/) and selects the largest
   .abcddb as the contacts DB.

2. handleSearch's SQL ran each LIKE clause against a single field, so a
   query like "Julie Thompson" never matched a contact whose first name
   is "Julie" and last name is "Thompson". Added an additional clause
   matching against (COALESCE(first_name,'') || ' ' || COALESCE(last_name,''))
   so multi-token full-name queries work.

Tested on macOS Sonoma with a ~2,300-contact iCloud library:
- Before: 0 contacts visible, all searches returned [].
- After: full search works; "Julie Thompson" finds the right record.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant