# /restart-ableton — Restart Ableton Live

Critical procedure after modifying remote script files. Clears Python bytecode cache so Ableton loads fresh code.

## Quick Version

```bash
bash scripts/restart_ableton.sh
```

## Manual Steps (if script fails)

```bash
# 1. Clear bytecode cache
find /home/alaarab/Sites/livemcp/remote_script -name "__pycache__" -type d -exec rm -rf {} + 2>/dev/null

# 2. Quit Ableton
osascript -e 'tell application "Ableton Live 12 Suite" to quit'
sleep 2

# 3. Dismiss save dialog
osascript -e 'tell application "System Events" to tell process "Ableton Live 12 Suite" to if exists window 1 then click button "Don'\''t Save" of window 1' 2>/dev/null

# 4. Wait for exit (max 15s)
for i in $(seq 1 15); do
  pgrep -x "Ableton Live" > /dev/null 2>&1 || break
  sleep 1
done

# 5. Force kill if hanging
pgrep -x "Ableton Live" > /dev/null 2>&1 && pkill -9 -x "Ableton Live" && sleep 2

# 6. Relaunch
open -a "Ableton Live 12 Suite"

# 7. Dismiss "unexpectedly quit" dialog (poll for 10s)
for i in $(seq 1 10); do
  osascript -e 'tell application "System Events" to tell process "Ableton Live 12 Suite" to if exists window 1 then click button "Reopen" of window 1' 2>/dev/null && break
  sleep 1
done

# 8. Wait for LiveMCP socket (port 9877)
for i in $(seq 1 30); do
  python3 -c "import socket; s=socket.socket(); s.settimeout(2); s.connect(('127.0.0.1', 9877)); s.close()" 2>/dev/null && break
  sleep 3
done
```

## Verify

1. Check Ableton status bar: "LiveMCP: Server started on port 9877"
2. Test MCP server: `uvx livemcp` (should connect)

## Common Issues

- **Cache not cleared**: Ableton loads old .pyc files → always clear `__pycache__` first
- **Save dialog blocks**: Script clicks "Don't Save" automatically
- **Socket timeout**: Takes 15-30s for port 9877 to be ready after launch
