I’ve recently upgraded my laptop (after the 6 years my previous MacBookPro latest) and I’ve now got one of these touchbar things. It’s cute, but I know that my laptop will be closed for 90% of the time and attach to an external monitor and keyboard.

That said, it absolutely does my head in that the control strip’s "play/pause" button will only control iTunes/Music. So I fixed that.

Karabiner Elements to the rescue[](#karabiner-elements-to-the-rescue)

I’ve been using [Karabiner Elements](https://karabiner-elements.pqrs.org/) for a while now and it’s a superb bit of software. It gives you complete control over the keyboard and sits in between and gives you the ability to completely change what the operating system actually sees.

So it stands to reason that I could capture the play/pause key press and completely take it over and send it to Spotify instead. It’s not quite that simple, but it’s no too far off.

Step one is to download and install Karabiner Elements. Once you’ve got that running, it needs to see the touch bar - which apparently announces itself as an entirely separate keyboard. So check this box:

![Karabiner Settings](/images/karabiner-settings.png)

Now Karabiner can see your keyboard - and a quick way to test this is to head to "Simple Modifications" and add "play\_or\_pause" and map it to (something like) "mute". Now test the play control strip button - if it mutes, then it’s working and the next step is to create a "complex modification" to control Spotify (you should remove the simple modification now).

Controlling Spotify[](#controlling-spotify)

From Karabiner Elements' preferences, on the Misc tab, click on the button the reads "Open config folder". This is where we’ll add the following in new JSON file. Under the directory complex_modifications (make it if it doesn’t exist), add this file as touchbar.json (or as you please):

{
  "title": "Touchbar",
  "rules": [
    {
      "description": "Play/Pause controls spotify",
      "manipulators": [
        {
          "from": { "consumer_key_code": "play_or_pause" },
          "to": [
            {
              "repeat": false,
              "halt": true,
              "shell_command": "osascript spotify-play.scpt"
            }
          ],
          "type": "basic"
        }
      ]
    }
  ]
}

This says: when the button pressed is play_or_pause then run an applescript and prevent the keyup. You can determine the key value from the Karabiner ElementsViewer that’s also installed.

The Apple Script[](#the-apple-script)

The last bit of the puzzle, you need to store this file in the same directory as the touchbar.json file (or change the location in the shell_command value).

using terms from application "Spotify"
  if player state of application "Spotify" is paused then
    tell application "Spotify" to play
  else
    tell application "Spotify" to pause
  end if
end using terms from

And that…should be it. I now have control over my own machine, which is frankly how it should always be.

Honourable mention to [Better Touch Tool](https://folivora.ai/) which looks like it might do the job, but I’m already familiar with Karabiner and Karabiner definitely does the job!

👍 32 likes

[![Laurie Jones](/images/no-user.svg "Laurie Jones")](![Ivan Čurić(/images/no-user.svg "Ivan Čurić")](![Dan Drayne(/images/no-user.svg "Dan Drayne")](![Javier Rincón(/images/no-user.svg "Javier Rincón")](![Paul Stone(/images/no-user.svg "Paul Stone")](![amar kanala(/images/no-user.svg "amar kanala")](![Guilherme Desimon(/images/no-user.svg "Guilherme Desimon")](![Oliver Ash(/images/no-user.svg "Oliver Ash")](![Jon 🇪🇺(/images/no-user.svg "Jon 🇪🇺")](![Christopher Siegel | fuercoaches.de(/images/no-user.svg "Christopher Siegel | fuercoaches.de")](![hanakimis(/images/no-user.svg "hanakimis")](![BaronessVonDonnerstag(/images/no-user.svg "BaronessVonDonnerstag")](![Iulian Safta(/images/no-user.svg "Iulian Safta")](![PMourelle(/images/no-user.svg "PMourelle")](![Kyle Halleman(/images/no-user.svg "Kyle Halleman")](![James Doc(/images/no-user.svg "James Doc")](![me, an internetual(/images/no-user.svg "me, an internetual")](![Mordern chief priest(/images/no-user.svg "Mordern chief priest")](![Shaun Bent 🇸🇪(/images/no-user.svg "Shaun Bent 🇸🇪")](![Maneesh Chiba(/images/no-user.svg "Maneesh Chiba")](![Derek(/images/no-user.svg "Derek")](![Urbian.(/images/no-user.svg "Urbian.")](![ibuch(/images/no-user.svg "ibuch")](![Stephen Cunliffe(/images/no-user.svg "Stephen Cunliffe")](![Vicky Chen(/images/no-user.svg "Vicky Chen")](![Jesper Wøldiche(/images/no-user.svg "Jesper Wøldiche")](![Simon Kunz(/images/no-user.svg "Simon Kunz")](![Marcel Jackwerth(/images/no-user.svg "Marcel Jackwerth")](![Bobby Duff(/images/no-user.svg "Bobby Duff")](![Steven Cracknell(/images/no-user.svg "Steven Cracknell")](![Bill Criswell(/images/no-user.svg "Bill Criswell")](![Paul Bastowski(/images/no-user.svg "Paul Bastowski")](https://twitter.com/pbastowski)

Comments

Lock Thread

Login

Add Comment[M ↓   Markdown]()

[Upvotes]()[Newest]()[Oldest]()

![](/images/no-user.svg)

James

0 points

3 years ago

Hi, I don’t understand the last part. Do I need to create a file where I input the text you provided? If so, what is the file extension for that? I have managed to make the button stop initiating Apple music, but now it doesn’t do anything. Thanks

[Commento](https://commento.io)