|
1 |
| -mac-spotify-rcd |
| 1 | +spotify-rcd |
2 | 2 | ===============
|
3 | 3 |
|
4 |
| -Makes the playback control keys on a MacBook Pro open spotify instead of iTunes. |
| 4 | +On a standard installation of macOS, pressing the playback control keys on an |
| 5 | +Apple keyboard opens iTunes if no other media applications are open. The purpose |
| 6 | +of this project is to patch this behavior such that Spotify is opened instead. |
| 7 | + |
| 8 | +## :warning: Compatibility |
| 9 | + |
| 10 | +This is the README for the legacy version of the project. The legacy version is |
| 11 | +known to work on a few older versions of macOS, but the exact list of supported |
| 12 | +versions is not known. |
| 13 | + |
| 14 | +Based on issues and commit dates, it seems reasonable to expect the legacy |
| 15 | +version to support macOS Mavericks (10.9) through Sierra (10.12). It's possible |
| 16 | +that some older versions of macOS could be supported as well. Compatibility with |
| 17 | +High Sierra (10.13) and newer is known to be broken. (Adding support for a newer |
| 18 | +version of macOS is being tracked by #3.) |
| 19 | + |
| 20 | +This tweak has been tested primarily using the internal keyboard of a MacBook |
| 21 | +Pro, but the tweak should also work with external keyboards. Compatibility with |
| 22 | +the MacBook Pro's Touch Bar is unknown. |
| 23 | + |
| 24 | +## How it works |
| 25 | + |
| 26 | +spotify-rcd works by [injecting][injection] itself into the `com.apple.rcd` |
| 27 | +system daemon, after which it uses [method swizzling][swizzling] to alter the |
| 28 | +daemon's behavior. |
| 29 | + |
| 30 | +(I'd recommend reading this section so that you know what the patch is actually |
| 31 | +doing to your system and what risks it comes with, but you can skip to the |
| 32 | +installation section if you're not interested in the technical details.) |
| 33 | + |
| 34 | +### Injection |
| 35 | + |
| 36 | +In order to load spotify-rcd into the system daemon, we take advantage of |
| 37 | +`DYLD_INSERT_LIBRARIES`, an environment variable that allows us to load custom |
| 38 | +images into other processes during launch. (At the moment, this injection vector |
| 39 | +works fine for the needs of this project. However, additional restrictions are |
| 40 | +placed on DYLD injection as part of each release of macOS, so it's likely only |
| 41 | +a matter of time before a new injection vector will be needed.) |
| 42 | + |
| 43 | +For `DYLD_INSERT_LIBRARIES` to work, we have to find some way of setting the |
| 44 | +environment variable in the target process before it is launched. Conveniently, |
| 45 | +macOS allows you to persistently unload system launch daemons and replace them |
| 46 | +with your own patched versions as long as the labels are different. As such, all |
| 47 | +we need to do for this to work is copy the system launch daemon configuration, |
| 48 | +alter the label to something unique, add our environment variable, and then use |
| 49 | +`launchctl` to persistently disable the system daemon and enable our patched |
| 50 | +version. |
| 51 | + |
| 52 | +### Swizzling |
| 53 | + |
| 54 | +Now that spotify-rcd has been injected into the system daemon, we actually need |
| 55 | +to alter the daemon's behavior to do what we want. This is where [method |
| 56 | +swizzling][swizzling] comes in. By intercepting all AppleScript execution, we |
| 57 | +can watch for any requests to launch iTunes and replace those with requests to |
| 58 | +launch Spotify instead. |
| 59 | + |
| 60 | +### Caveats |
| 61 | + |
| 62 | +As you can imagine, all of this can be a somewhat fragile process. It's possible |
| 63 | +that any release of macOS can break the injection *or* the swizzling. Even so, |
| 64 | +this patch tends to be relatively safe. |
| 65 | + |
| 66 | +Unlike other versions of this tweak, installation doesn't require modifying any |
| 67 | +system files. The tweak can also be reverted by simply disabling the patched |
| 68 | +daemon and enabling the unpatched daemon. Given that `com.apple.rcd` isn't a |
| 69 | +critical system service, this makes the liklihood of serious side-effects very |
| 70 | +unlikely. |
| 71 | + |
| 72 | +[injection]: https://knight.sc/malware/2019/03/15/code-injection-on-macos.html |
| 73 | +[swizzling]: https://nshipster.com/method-swizzling/ |
5 | 74 |
|
6 | 75 | ## Installation
|
7 | 76 |
|
@@ -42,11 +111,18 @@ Makes the playback control keys on a MacBook Pro open spotify instead of iTunes.
|
42 | 111 | $ launchctl load -w /Library/LaunchAgents/com.apple.rcd.patched.plist
|
43 | 112 | ```
|
44 | 113 |
|
45 |
| -## Disabling |
| 114 | +## Uninstallation |
46 | 115 |
|
47 | 116 | To disable the tweak, simply unload the modified plist and load the original:
|
48 | 117 |
|
49 | 118 | ```
|
50 | 119 | $ launchctl unload -w /Library/LaunchAgents/com.apple.rcd.patched.plist
|
51 | 120 | $ launchctl load -w /System/Library/LaunchAgents/com.apple.rcd.plist
|
52 | 121 | ```
|
| 122 | +
|
| 123 | +After the tweak has been disabled, you can completely uninstally it by simply |
| 124 | +deleting the tweak bundle: |
| 125 | +
|
| 126 | +``` |
| 127 | +$ rm -rf "/Library/Application Support/Tweaks/SpotifyRCD.bundle" |
| 128 | +``` |
0 commit comments