Skip to content

Instantly share code, notes, and snippets.

@jamesmoss
Created February 25, 2026 17:17
Show Gist options
  • Select an option

  • Save jamesmoss/7bc22101946e0b0a4a12fc6819500c4b to your computer and use it in GitHub Desktop.

Select an option

Save jamesmoss/7bc22101946e0b0a4a12fc6819500c4b to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
# Replace the choo-choo.mp3 sound in the Conductor app with a custom MP3 file.
# Usage: ./replace-conductor-sound.sh <path-to-mp3>
#
# Requirements: ffmpeg, python3, brotli (pip)
CONDUCTOR_BIN="/Applications/Conductor.app/Contents/MacOS/conductor"
BACKUP_PATH="/tmp/conductor-backup-$(date +%s)"
MAX_RAW_BYTES=24960 # original decompressed MP3 size
MAX_COMPRESSED_BYTES=23164 # available slot in the binary
DATA_START=$((0x1be6666))
DATA_END=$((0x1bec0e2))
if [[ $# -ne 1 ]]; then
echo "Usage: $0 <path-to-mp3>"
exit 1
fi
INPUT_MP3="$1"
if [[ ! -f "$INPUT_MP3" ]]; then
echo "Error: file not found: $INPUT_MP3"
exit 1
fi
if [[ ! -f "$CONDUCTOR_BIN" ]]; then
echo "Error: Conductor not found at $CONDUCTOR_BIN"
exit 1
fi
# Check dependencies
if ! command -v ffmpeg &>/dev/null; then
echo "Error: ffmpeg is required. Install with: brew install ffmpeg"
exit 1
fi
if ! python3 -c "import brotli" &>/dev/null; then
echo "Error: python3 brotli module is required. Install with: pip3 install brotli"
exit 1
fi
echo "Backing up original binary to $BACKUP_PATH"
cp "$CONDUCTOR_BIN" "$BACKUP_PATH"
# Re-encode the MP3 to fit within the available space
# Start at 80kbps mono, reduce if needed
TEMP_MP3="$(mktemp /tmp/conductor-sound-XXXXXX.mp3)"
trap 'rm -f "$TEMP_MP3"' EXIT
BITRATE=80
while [[ $BITRATE -ge 32 ]]; do
ffmpeg -y -i "$INPUT_MP3" -ac 1 -b:a "${BITRATE}k" \
-map_metadata -1 -write_xing 0 -id3v2_version 0 \
"$TEMP_MP3" 2>/dev/null
SIZE=$(stat -f%z "$TEMP_MP3")
if [[ $SIZE -le $MAX_RAW_BYTES ]]; then
echo "Encoded at ${BITRATE}kbps mono: ${SIZE} bytes (limit: ${MAX_RAW_BYTES})"
break
fi
echo "Too large at ${BITRATE}kbps (${SIZE} bytes), trying lower..."
BITRATE=$((BITRATE - 16))
done
if [[ $(stat -f%z "$TEMP_MP3") -gt $MAX_RAW_BYTES ]]; then
echo "Error: could not encode MP3 small enough to fit. Try a shorter audio clip."
echo "Restoring backup..."
cp "$BACKUP_PATH" "$CONDUCTOR_BIN"
exit 1
fi
# Patch the binary
python3 - "$CONDUCTOR_BIN" "$TEMP_MP3" "$DATA_START" "$DATA_END" << 'PYEOF'
import sys, brotli
bin_path, mp3_path = sys.argv[1], sys.argv[2]
data_start, data_end = int(sys.argv[3]), int(sys.argv[4])
slot_size = data_end - data_start
with open(mp3_path, "rb") as f:
new_mp3 = f.read()
compressed = brotli.compress(new_mp3, quality=11)
if len(compressed) > slot_size:
print(f"Error: compressed size ({len(compressed)}) exceeds slot ({slot_size})")
sys.exit(1)
with open(bin_path, "rb") as f:
binary = bytearray(f.read())
# Verify the path string is where we expect
path_offset = data_start - 14
if binary[path_offset:data_start] != b"/choo-choo.mp3":
print("Error: choo-choo.mp3 path not found at expected offset.")
print("The Conductor binary may have changed. Aborting.")
sys.exit(1)
padded = compressed + b"\x00" * (slot_size - len(compressed))
binary[data_start:data_end] = padded
# Verify roundtrip
test = brotli.decompress(bytes(binary[data_start:data_start + len(compressed)]))
assert test == new_mp3, "Roundtrip verification failed"
with open(bin_path, "wb") as f:
f.write(binary)
print(f"Patched: {len(compressed)} bytes compressed ({slot_size - len(compressed)} bytes padding)")
PYEOF
# Re-sign the app
echo "Re-signing Conductor.app..."
codesign --force --sign - /Applications/Conductor.app
echo ""
echo "Done! Restart Conductor to hear the new sound."
echo "To restore the original: cp '$BACKUP_PATH' '$CONDUCTOR_BIN' && codesign --force --sign - /Applications/Conductor.app"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment