#!/bin/bash # LogiSwitch for macOS - build a support report to paste into any Claude chat. # Starts with instructions for Claude, then diagnostics, log and full source. # Removes: macOS username, computer/host name, hardware addresses. # Saves to the Desktop, copies to the clipboard, opens it in TextEdit. DIR="$HOME/Library/Application Support/LogiSwitch" PLIST="$HOME/Library/LaunchAgents/com.logiswitch.agent.plist" SRC="$(cd "$(dirname "$0")" && pwd)" TMP="$(mktemp -t logiswitch)" # bash report.sh -> asks for a description, saves to Desktop, copies, opens # bash report.sh --auto "reason" -> used by the app itself when it detects a problem: no # questions; saves to the fixed path last-problem-report.txt # (Claude Code can read it directly) and to the Desktop, then notifies AUTO=0 if [ "${1:-}" = "--auto" ]; then AUTO=1 PROBLEM="AUTOMATIC REPORT (created by LogiSwitch itself, no user description). Detected problem: ${2:-unknown}" OUT="$DIR/last-problem-report.txt" else PROBLEM="${1:-}" OUT="$HOME/Desktop/LogiSwitch-mac-report-$(date +%Y%m%d-%H%M).txt" fi mkdir -p "$DIR" if [ "$AUTO" = 0 ] && [ -z "$PROBLEM" ]; then PROBLEM="$(osascript -e 'try' -e 'text returned of (display dialog "Briefly describe the problem (what you did, what happened, what you expected):" default answer "" with title "LogiSwitch support report")' -e 'end try' 2>/dev/null)" fi esc() { printf '%s' "$1" | sed -e 's/[]\/$*.^[]/\\&/g'; } USER_RE="$(esc "$(id -un)")" COMP_RE="$(esc "$(scutil --get ComputerName 2>/dev/null)")" HOST_RE="$(esc "$(hostname -s 2>/dev/null)")" SED_ARGS=(-e "s/$USER_RE//g") if [ -n "$COMP_RE" ]; then SED_ARGS+=(-e "s/$COMP_RE//g"); fi if [ -n "$HOST_RE" ]; then SED_ARGS+=(-e "s/$HOST_RE//g"); fi redact() { sed "${SED_ARGS[@]}" | sed -E 's/([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}//g' } # Live device check (read-only), max 40 s. LIVE="(LogiSwitch binary not found)" if [ -x "$DIR/LogiSwitch" ]; then ( "$DIR/LogiSwitch" --list > "$TMP" 2>&1 ) & pid=$! for _ in $(seq 1 40); do kill -0 "$pid" 2>/dev/null || break; sleep 1; done kill "$pid" 2>/dev/null && echo "(timed out)" >> "$TMP" LIVE="$(cat "$TMP")" fi { cat <<'EOF' ===== INSTRUCTIONS FOR CLAUDE ===== You are helping me fix "LogiSwitch", a small tool that switches my Logitech keyboard and mouse between my Windows PC and my Mac. This report is from the MAC side (Swift menu-bar app). How it works: - It sends the Logitech HID++ 2.0 "Change Host" command (feature 0x1814, function 1 setCurrentHost, host index 0-based) to every connected Logitech device that supports it. Local HID (IOKit). The only network use is the optional clipboard sync (see below). - Bluetooth devices: HID interface with primary usage page 0xFF43, long report ID 0x11 (20 bytes, report ID included in the buffer), device index 0xFF. Unifying/Bolt receivers: primary usage page 0xFF00, device index 1-6, errors arrive as short report 0x10 with sub-id 0x8F. - The app polls NSEvent.mouseLocation; when the cursor is held against the outer screen edge facing the PC (middle 80% of the height, no button held) for 300 ms, it switches all devices to the PC's channel. The cursor stays on the edge; it re-arms only after leaving the edge. - Devices are remembered in devices.json and re-detected every 3 minutes, so a new keyboard/mouse set (e.g. at work) is picked up automatically. - Installed per user to ~/Library/Application Support/LogiSwitch, built with `xcrun swiftc -O -o LogiSwitch LogiSwitch.swift -framework AppKit -framework IOKit`, started by the user LaunchAgent ~/Library/LaunchAgents/com.logiswitch.agent.plist. - The Windows side is a separate PowerShell tool in the same package (Install.cmd). Constraints (must keep): no admin password, no internet or third-party services, and network only for the optional clipboard sync (off until turned on; the Mac listens on TCP 51888, the PC dials out, AES-256 + HMAC with a shared pairing code), no file sharing. Ask me before granting any macOS permission. What I need from you: 1. Read my problem, the diagnostics and logs below, and identify the root cause. 2. Give me the fix: exact Terminal commands, or the complete corrected file(s) (full content, ready to save over the old one), then how to reinstall (bash install.sh in the folder with the corrected files, or menu bar icon > Update). 3. Tell me how to confirm it is fixed. If you can run commands on this Mac (for example Claude Code), apply the fix yourself instead: the installed files are in ~/Library/Application Support/LogiSwitch (it is also a complete install package); after editing, run bash ~/Library/Application\ Support/LogiSwitch/install.sh and verify with ".../LogiSwitch --list" and watch.log. The latest automatic report is always at ~/Library/Application Support/LogiSwitch/last-problem-report.txt. EOF echo echo "===== MY PROBLEM =====" echo "${PROBLEM:-(not described)}" echo echo "===== SYSTEM =====" echo "Report created : $(date '+%Y-%m-%d %H:%M:%S')" echo "LogiSwitch : $(cat "$DIR/version.txt" 2>/dev/null || echo 'not installed')" sw_vers 2>/dev/null echo "Architecture : $(uname -m)" echo "Swift compiler : $(xcrun swiftc --version 2>&1 | head -1)" echo echo "===== AGENT STATUS =====" echo "LaunchAgent plist present: $([ -f "$PLIST" ] && echo yes || echo no)" launchctl print "gui/$(id -u)/com.logiswitch.agent" 2>&1 | grep -E '^\s*(state|pid|last exit code|runs) ' || echo "(agent not loaded)" pgrep -fl "Application Support/LogiSwitch/LogiSwitch$" || echo "(app process not running)" echo echo "===== SETTINGS (settings.json) =====" cat "$DIR/settings.json" 2>/dev/null || echo "(none)" echo echo "===== REMEMBERED DEVICES (devices.json) =====" cat "$DIR/devices.json" 2>/dev/null || echo "(none)" echo echo "===== LIVE DEVICE CHECK (LogiSwitch --list, read-only) =====" echo "$LIVE" echo echo "===== DISPLAYS =====" system_profiler SPDisplaysDataType 2>/dev/null | grep -E 'Resolution|Main Display|Mirror|Online|Display Type' || echo "?" echo echo "===== LOGITECH BLUETOOTH DEVICES =====" system_profiler SPBluetoothDataType 2>/dev/null | grep -iE -A4 'logi|mx |ergo|k[0-9]{3}|m[0-9]{3}|lift|pebble|signature' | grep -vE 'Address|Serial' || echo "(none found)" echo echo "===== LOG (last 150 lines of watch.log) =====" tail -n 150 "$DIR/watch.log" 2>/dev/null || echo "(none)" echo echo "===== STDERR (last 50 lines) =====" tail -n 50 "$DIR/stderr.log" 2>/dev/null || echo "(none)" echo echo "===== INSTALL LOG (last 60 lines) =====" tail -n 60 "$DIR/install.log" 2>/dev/null || echo "(none)" } | redact > "$OUT" # Source code (not redacted; contains no personal data). for f in LogiSwitch.swift install.sh uninstall.sh report.sh; do p="$DIR/$f"; [ -f "$p" ] || p="$SRC/$f" { echo; echo "===== SOURCE: $f ====="; cat "$p" 2>/dev/null || echo "(missing)"; } >> "$OUT" done echo; echo "===== END OF REPORT =====" >> "$OUT" rm -f "$TMP" if [ "$AUTO" = 1 ]; then cp -f "$OUT" "$HOME/Desktop/LogiSwitch-problem-report.txt" 2>/dev/null || true osascript -e 'display notification "A report for Claude was saved to your Desktop (LogiSwitch-problem-report.txt). Menu bar icon > Open automatic problem report copies it; then paste it into any Claude chat." with title "LogiSwitch found a problem"' 2>/dev/null || true echo "Automatic report saved to $OUT and the Desktop." else pbcopy < "$OUT" open -e "$OUT" echo "Report saved to $OUT (also copied to the clipboard)." fi