Skip to content

Instantly share code, notes, and snippets.

@mislav
Last active May 4, 2023 11:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mislav/4030afba9577443d4ad6 to your computer and use it in GitHub Desktop.
Save mislav/4030afba9577443d4ad6 to your computer and use it in GitHub Desktop.
Patch installer for OS X `rcd` daemon to make headset remote buttons start/stop Spotify instead of iTunes. The pause/resume functionality still doesn't work unless iTunes is running in the background, for some inexplicable reason.
#!/bin/bash
# Run once to patch `rcd` daemon after creating a backup.
# Run again to restore the backup and revert back to original functionality.
set -eu
if [ "$USER" != "root" ]; then
exec sudo "$0" "$@"
fi
rcd="/System/Library/CoreServices/rcd.app/Contents/MacOS/rcd"
killall -KILL rcd 2>/dev/null || true
if [ ! -e "${rcd}.noSpotify" ]; then
mv -v "$rcd"{,.noSpotify}
/usr/bin/ruby -e '
bin_contents = File.open(ARGV[0], "rb") { |source| source.read }
File.open(ARGV[1], "wb") { |dest|
dest.write bin_contents.gsub(
%{application id "com.apple.iTunes"},
%{application "Spotify" }
)
}
' "$rcd"{.noSpotify,}
chmod +x "$rcd"
codesign -f -s - "$rcd"
echo "Now controlling Spotify."
else
mv -v "$rcd"{.noSpotify,}
echo "Now controlling iTunes."
fi
launchctl start "com.apple.rcd"
@fine-fiddle
Copy link

fine-fiddle commented Jun 3, 2021

I'm trying to adapt this fix to the SIP world, thinking I could copy the RCD app, modify it, unload /System/Library/LaunchAgents/com.apple.rcd.plist and make a new launch agent to point to the modded copy of rcd.app.

However, rcd.app seems to have changed, like I don't see com.apple.itunes from strings /System/Library/CoreServices/rcd.app/Contents/MacOS/rcd

Do you have any tips about how you figured out the bin_contents.gsub( iTunes, Spotify) bit? Thats where I'm currently stuck.

@wwmoraes
Copy link

@fine-fiddle the rcd daemon, up to Sierra (10.12), used AppleScript to launch iTunes. You could find this line on it:

tell application id \"com.apple.iTunes\" to launch

The patch solution then was to replace the iTunes bundle ID with the target application's, or just the application name. That's exactly how this patch, spotify-rcd and Farhan Ahmad's Play Button iTunes Patch worked originally.

However since High Sierra (10.13), Apple has rewritten the rcd daemon, and it is now a proper binary. There's no reference to AppleScript or even iTunes on its strings in these versions, which now renders all those solutions defunct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment