From 1c3f6b04c9008d79957d4f7274dd97eebd4cab84 Mon Sep 17 00:00:00 2001 From: Ryan Pendleton Date: Sat, 3 Oct 2020 13:28:43 -0600 Subject: [PATCH 1/4] update version to pre-release 0.1.0 --- SpotifyRCD/SpotifyRCD-Info.plist | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SpotifyRCD/SpotifyRCD-Info.plist b/SpotifyRCD/SpotifyRCD-Info.plist index d40e82e..bdc186e 100644 --- a/SpotifyRCD/SpotifyRCD-Info.plist +++ b/SpotifyRCD/SpotifyRCD-Info.plist @@ -17,11 +17,11 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.0 + 0.1.0 CFBundleSignature ???? CFBundleVersion - 1 + 0 NSHumanReadableCopyright Copyright © 2014 Inline-Studios. All rights reserved. NSPrincipalClass From 423eee5a508dc5d4b1c233c0e3b07ec2928744de Mon Sep 17 00:00:00 2001 From: Ryan Pendleton Date: Sat, 3 Oct 2020 14:09:04 -0600 Subject: [PATCH 2/4] add documentation regarding the legacy version --- README.md | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ae8c64f..26ce7e8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,25 @@ -mac-spotify-rcd +spotify-rcd =============== -Makes the playback control keys on a MacBook Pro open spotify instead of iTunes. +On a standard installation of macOS, pressing the playback control keys on an +Apple keyboard opens iTunes if no other media applications are open. The purpose +of this project is to patch this behavior such that Spotify is opened instead. + +## :warning: Compatibility + +This is the README for the legacy version of the project. The legacy version is +known to work on a few older versions of macOS, but the exact list of supported +versions is not known. + +Based on issues and commit dates, it seems reasonable to expect the legacy +version to support macOS Mavericks (10.9) through Sierra (10.12). It's possible +that some older versions of macOS could be supported as well. Compatibility with +High Sierra (10.13) and newer is known to be broken. (Adding support for a newer +version of macOS is being tracked by #3.) + +This tweak has been tested primarily using the internal keyboard of a MacBook +Pro, but the tweak should also work with external keyboards. Compatibility with +the MacBook Pro's Touch Bar is unknown. ## Installation @@ -42,7 +60,7 @@ Makes the playback control keys on a MacBook Pro open spotify instead of iTunes. $ launchctl load -w /Library/LaunchAgents/com.apple.rcd.patched.plist ``` -## Disabling +## Uninstallation To disable the tweak, simply unload the modified plist and load the original: @@ -50,3 +68,10 @@ To disable the tweak, simply unload the modified plist and load the original: $ launchctl unload -w /Library/LaunchAgents/com.apple.rcd.patched.plist $ launchctl load -w /System/Library/LaunchAgents/com.apple.rcd.plist ``` + +After the tweak has been disabled, you can completely uninstally it by simply +deleting the tweak bundle: + +``` +$ rm -rf /Library/Application Support/Tweaks/SpotifyRCD.bundle +``` From fd47fd25e0325c8998cfbf782485aef4b2b8e2a0 Mon Sep 17 00:00:00 2001 From: Ryan Pendleton Date: Sat, 3 Oct 2020 14:09:39 -0600 Subject: [PATCH 3/4] add documentation on how the tweak works --- README.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/README.md b/README.md index 26ce7e8..fe1c2f5 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,57 @@ This tweak has been tested primarily using the internal keyboard of a MacBook Pro, but the tweak should also work with external keyboards. Compatibility with the MacBook Pro's Touch Bar is unknown. +## How it works + +spotify-rcd works by [injecting][injection] itself into the `com.apple.rcd` +system daemon, after which it uses [method swizzling][swizzling] to alter the +daemon's behavior. + +(I'd recommend reading this section so that you know what the patch is actually +doing to your system and what risks it comes with, but you can skip to the +installation section if you're not interested in the technical details.) + +### Injection + +In order to load spotify-rcd into the system daemon, we take advantage of +`DYLD_INSERT_LIBRARIES`, an environment variable that allows us to load custom +images into other processes during launch. (At the moment, this injection vector +works fine for the needs of this project. However, additional restrictions are +placed on DYLD injection as part of each release of macOS, so it's likely only +a matter of time before a new injection vector will be needed.) + +For `DYLD_INSERT_LIBRARIES` to work, we have to find some way of setting the +environment variable in the target process before it is launched. Conveniently, +macOS allows you to persistently unload system launch daemons and replace them +with your own patched versions as long as the labels are different. As such, all +we need to do for this to work is copy the system launch daemon configuration, +alter the label to something unique, add our environment variable, and then use +`launchctl` to persistently disable the system daemon and enable our patched +version. + +### Swizzling + +Now that spotify-rcd has been injected into the system daemon, we actually need +to alter the daemon's behavior to do what we want. This is where [method +swizzling][swizzling] comes in. By intercepting all AppleScript execution, we +can watch for any requests to launch iTunes and replace those with requests to +launch Spotify instead. + +### Caveats + +As you can imagine, all of this can be a somewhat fragile process. It's possible +that any release of macOS can break the injection *or* the swizzling. Even so, +this patch tends to be relatively safe. + +Unlike other versions of this tweak, installation doesn't require modifying any +system files. The tweak can also be reverted by simply disabling the patched +daemon and enabling the unpatched daemon. Given that `com.apple.rcd` isn't a +critical system service, this makes the liklihood of serious side-effects very +unlikely. + +[injection]: https://knight.sc/malware/2019/03/15/code-injection-on-macos.html +[swizzling]: https://nshipster.com/method-swizzling/ + ## Installation - Automated Installation: This project contains an `install.sh` script that will From 421589bb2b0c72865108d94dc0ff612ae98af764 Mon Sep 17 00:00:00 2001 From: Ryan Pendleton Date: Sat, 3 Oct 2020 14:14:42 -0600 Subject: [PATCH 4/4] fix incorrect uninstallation command --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fe1c2f5..26e5a53 100644 --- a/README.md +++ b/README.md @@ -124,5 +124,5 @@ After the tweak has been disabled, you can completely uninstally it by simply deleting the tweak bundle: ``` -$ rm -rf /Library/Application Support/Tweaks/SpotifyRCD.bundle +$ rm -rf "/Library/Application Support/Tweaks/SpotifyRCD.bundle" ```