iCloud Sync Doctor

A Python utility to diagnose macOS iCloud Drive sync loops, force download signals for local packages, and purge lock files.

Python macOS Terminal POSIX Signals System Automation
View Repository
Screenshot of iCloud Sync Doctor

iCloud Sync Doctor

iCloud Sync Doctor is a local script utility built to fix a recurring issue faced by developers using macOS with active iCloud Drive desktop synchronization: file sync freezes, infinite processing loops, and missing cloud documents during local compilation.

The script targets macOS’s local cloud management daemon (bird), purging dead lock files and signaling force-downloads for missing workspace directories.

The Problem

macOS iCloud Drive dynamically archives rarely-used files to the cloud to save local disk space, replacing them with virtual reference files (.icloud). When a developer runs terminal commands (like npm install or python build.py), compilation scripts scan directories and crash when encountering these reference files because they cannot read their contents.

Furthermore, during heavy read/write operations in code folders, iCloud often gets stuck in infinite synchronization conflicts, locking up files and consuming high CPU resources.

+-----------------------------------------------------------+
|                   Local Coding Workspace                  |
|  - Active read/writes (e.g. node_modules, temp files)     |
|  - Programmatic locks triggered                           |
+-----------------------------------------------------------+
                             |
                  [iCloud Sync Doctor Script]
                             |
                             v
+-----------------------------------------------------------+
|                     System Diagnosis Hub                  |
|  - Identifies locked and virtual .icloud placeholder files|
|  - Monitors bird process CPU usage and thread status       |
+-----------------------------------------------------------+
                             |
                             v
+-----------------------------------------------------------+
|                   FS Intervention Layer                   |
|  - Triggers force-download flags via `brtool` / `open`     |
|  - Purges hidden lock files (.DS_Store conflicts)         |
|  - Restarts system `bird` daemon gracefully               |
+-----------------------------------------------------------+

Key Mechanisms Implemented

1. Placeholder File Identification

The script recursively scans directories looking for files prefixed with . and suffixed with .icloud. These represent virtual files that exist in the cloud but are missing locally.

2. Programmatic Download Triggering

Instead of forcing the user to manually click “Download Now” in Finder for dozens of files, the script uses the macOS Finder API and command-line commands to request immediate retrieval of the target assets.

3. Graceful Daemon Cycling

If iCloud’s sync service (bird or cloudd) becomes unresponsive (characterized by 100%+ CPU usage in system monitor logs), the script executes a graceful termination signal. This forces the OS to restart the daemon, clean its internal indexing tables, and re-index the project folder correctly without risking data loss.

4. Git Folder Exclusions

To save internet bandwidth and prevent conflicts, the script automatically parses .gitignore rules, instructing the cloud service to ignore massive directory trees like node modules or virtual environments (.venv).