Skip to content

Instantly share code, notes, and snippets.

@al3rez
Created July 9, 2026 04:12
Show Gist options
  • Select an option

  • Save al3rez/9bda77c2a0ddab0fd02aa7ffdbe0fa4a to your computer and use it in GitHub Desktop.

Select an option

Save al3rez/9bda77c2a0ddab0fd02aa7ffdbe0fa4a to your computer and use it in GitHub Desktop.
Sync Linux (Wayland) clipboard to a remote Mac over SSH — images + text, paste straight into Claude Code on the Mac
[Unit]
Description=Sync clipboard to mac-mini
After=graphical-session.target
PartOf=graphical-session.target
[Service]
ExecStart=/usr/bin/wl-paste --watch %h/.local/bin/clipsync-to-mac
Restart=on-failure
RestartSec=3
[Install]
WantedBy=graphical-session.target
#!/bin/bash
# Push local Wayland clipboard to mac-mini's clipboard (images + text).
# Invoked by `wl-paste --watch` on every clipboard change.
HOST=mac-mini
SSH="ssh -o ControlMaster=auto -o ControlPath=/tmp/.clipsync-%r@%h -o ControlPersist=600 -o ConnectTimeout=3 $HOST"
STATE=/tmp/.clipsync-last-hash
types=$(wl-paste --list-types 2>/dev/null)
if grep -q 'image/png' <<<"$types"; then
data=$(wl-paste --type image/png | base64)
kind=image
elif grep -q 'text/plain' <<<"$types"; then
data=$(wl-paste --no-newline --type text/plain | base64)
kind=text
else
exit 0
fi
[ -z "$data" ] && exit 0
# skip if unchanged (wl-paste --watch can fire repeatedly)
hash=$(sha256sum <<<"$data" | cut -d' ' -f1)
[ -f "$STATE" ] && [ "$(cat "$STATE")" = "$hash" ] && exit 0
echo "$hash" > "$STATE"
if [ "$kind" = image ]; then
base64 -d <<<"$data" | $SSH 'cat > /tmp/.clipsync.png && osascript -e "set the clipboard to (read (POSIX file \"/tmp/.clipsync.png\") as «class PNGf»)"'
else
base64 -d <<<"$data" | $SSH pbcopy
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment