Bidirectional clipboard sync between Mac and Android over LAN. Copy on one device, paste on the other — no BLE, no cloud, no third-party servers.
| Scenario | Behavior |
|---|---|
| Copy on Mac | Clipboard syncs to Android instantly |
| Copy on Android | Clipboard syncs to Mac instantly |
| VPN active | Works — LAN traffic bypasses VPN tunnel |
| Terminal closed | Keeps running — launchd on Mac, nohup on Android |
| Phone reboot | Auto-restarts via Termux:Boot |
| IP changed | Android re-resolves Mac via mDNS on failure |
| Mac restarted | Android sends keepalive every 30s, Mac re-learns Android IP |
- Android resolves Mac via
<hostname>.localmDNS — no hardcoded IPs - On startup, Android sends an initial ping so Mac immediately learns Android's IP
- Android sends a keepalive every 30s so Mac never loses track of Android's IP
- Each side runs a TCP server on port
59876and polls clipboard every 0.5s - On change, pushes to the other device via length-prefixed TCP message
- A 1.5s cooldown suppresses echo loops after receiving from remote
- Mac uses
launchctl asuser <uid> pbcopy/pbpaste— works correctly from launchd daemons
Mac
- Python 3 (system
/usr/bin/python3)
Android
- Termux — F-Droid only, not Play Store
- Termux:API — F-Droid
- Termux:Boot — F-Droid
Play Store versions of Termux are outdated. Use F-Droid.
sudo cp clipsyncd_mac.py /usr/local/bin/clipsyncd.py
sudo chmod 644 /usr/local/bin/clipsyncd.pyCreate ~/Library/LaunchAgents/com.user.clipsyncd.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.user.clipsyncd</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/python3</string>
<string>/usr/local/bin/clipsyncd.py</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/clipsyncd.log</string>
<key>StandardErrorPath</key>
<string>/tmp/clipsyncd.log</string>
</dict>
</plist>launchctl load ~/Library/LaunchAgents/com.user.clipsyncd.plistEdit clipsyncd_android.py and set:
MAC_HOSTNAME = "your-mac-hostname.local"Get your hostname with hostname on Mac.
pkg install termux-api python
cp clipsyncd_android.py ~/clipsyncd.py
nohup python3 ~/clipsyncd.py > ~/clipsyncd.log 2>&1 &Open Termux:Boot app once to activate it, then:
mkdir -p ~/.termux/boot
cat > ~/.termux/boot/clipsyncd.sh << 'EOF'
#!/data/data/com.termux/files/usr/bin/bash
termux-wake-lock
nohup python3 ~/clipsyncd.py > ~/clipsyncd.log 2>&1 &
EOF
chmod +x ~/.termux/boot/clipsyncd.shDisable battery optimization: Settings > Apps > Termux > Battery > Unrestricted
Mac
# check status
launchctl list | grep clipsyncd
# live log
tail -f /tmp/clipsyncd.log
# restart
launchctl unload ~/Library/LaunchAgents/com.user.clipsyncd.plist
launchctl load ~/Library/LaunchAgents/com.user.clipsyncd.plistAndroid (Termux)
# check status
pgrep -f clipsyncd.py && echo running || echo stopped
# live log
tail -f ~/clipsyncd.log
# restart
pkill -f clipsyncd.py
nohup python3 ~/clipsyncd.py > ~/clipsyncd.log 2>&1 &| Problem | Fix |
|---|---|
| Android script stops after a while | Settings > Apps > Termux > Battery > Unrestricted |
| Mac not receiving from Android | Check sudo lsof -i :59876 — port must be listening |
| Android can't resolve Mac hostname | Make sure both devices are on same WiFi |
| Works on WiFi but not with VPN | Add Termux to VPN split tunnel bypass list on Android |
| Echo loop | Cooldown is 1.5s — increase REMOTE_SET_COOLDOWN if needed |
| Resource | Usage |
|---|---|
| CPU | Near zero — sleeps 0.5s between polls |
| RAM | ~15MB |
| Battery | Minimal — no GPS, pure TCP |
| Network | LAN only, direct peer-to-peer |
| Contributor | Role |
|---|---|
| chakri192 | Author |
| aider | AI pair programmer |
README and code contributions assisted by aider using local LLMs via Ollama:
| Model | Used for |
|---|---|
qwen2.5-coder:7b |
Code suggestions, refactoring |
llama3.1:8b |
Prose, documentation, commit messages |
MIT