The software Beardedspice provides a user-friendly approach to prioritizing Spotify for your media keys. It runs in the background and gives you a few simple settings in the Mac menu bar. It just works.
Download and installation
It can be downloaded and installed directly from the Beardedspice homepage, or by using e.g. Homebrew:
brew install --cask beardedspice
Notes
- It is compatible with macOS Big Sur.
- Ensure the application is given sufficient privileges in Security & Privacy in the System Preferences.
- Beardedspice supports controlling a vast amount of media players. Simply disable any unwanted players, while keeping Spotify enabled.
- I am not affiliated with the developer(s), I am just a satisfied user.
Update 2021-01-16 - Use Beardedspice as the alternative app Mac Media Key Forwarder is no longer being updated
As there are reports of Mac Media Key Forwarder not working for some users, and the developer no longer updating the app, it is recommended to use Beardedspice.
Nevertheless, Mac Media Key Forwarder will still work fine for most people running on e.g. MacOS High Sierra, Mojave, Catalina, or Big Sur so it remains an alternative.
Download and installation
It can be downloaded and installed directly from GitHub, or by using e.g. Homebrew:
brew install --cask macmediakeyforwarder
You can create AppleScript's that do things such as play/pause, next track, previous track and then using the Microsoft keyboard pref panel set the key settings for the media keys to use command "Open Item" and then choose the apple script that corresponds with the media key you wish to use.
Here is a link to what the apple scripts should look like.
http://www.jack.sh/2011/07/21/spotify-applescripts-0-5-2/
Honestly, I simply opened Automator, create new application, added action "run appleScript" and for the area where the script goes, added:
tell application "Spotify" to playpause
Next, I assigned that application to the play/pause media key.
For next track and previous track the script should just be
tell application "Spotify" to next track
or
tell application "Spotify" to previous track
Best Answer
If you use the Spotify desktop app, the media keys on OS X work by default (sometimes iTunes randomly "retains" the keys: just reboot). For the best results, don't keep iTunes and Spotify open at the same time.
If you use the Spotify Web Player, you can enable the media keys using BeardedSpice, a free application which enables you to control web-based media players using you keyboard media keys. It also works for YouTube, for example.