If you have a "TouchBar enabled MacBook™️" you may have asked yourself how to include it into your daily workflow.

Some assign shortcuts to app-related functions, other may disable it completely in favor of the fn keys but I will show you how to transform your TouchBar into a Soundboard!

Step 1: Install youtube-dl and ffmpeg

I will use the CLI tool youtube-dl which allows us to download and convert YouTube videos with a clean and understandable API.

Please note that youtube-dl requires ffmpeg to extract the audio track out of the downloaded videos.

$ brew update
$ brew install youtube-dl ffmpeg

youtube-dl is a powerful tool with a lot of flags and options included.
I'd suggest you to take a look at the output of youtube-dl --help to get an overview of it's capabilities, but for now we only need to know three options to get started:

-x -> Extract the audio track from the downloaded YouTube video
--audio-format -> Specify an audio format to convert the audio track to. I will use "mp3" but feel free to choose any format you desire.

Step 2: Gathering sounds

I chose the Windows XP Error Tone for our example, because I like the aggressive phonetics of it and it may be suitable for annoying coworkers.

That sound brings up memories...

So let's create a directory for our sounds and download the example.

$ mkdir -p ~/soundboard
$ cd $_
$ youtube-dl -x --audio-format mp3 https://www.youtube.com/watch?v=iqztd7uMvVI

Step 3: Create a "Quick Action" for the sound

To call our sounds from the TouchBar we need to create a so called "Quick Action" inside Automator.
So open Automator and choose the menu File > New or press ⌘ + N and then choose "Quick Action".

Select "Quick Action" inside the Automator creation prompt and click "Choose"

If you are unfamiliar with how to use Automator, here is a little explainer of the important parts of the Application:

Inside the red area we see the library. Here we may choose from predefined actions to run if our workflow gets triggered. There's a lot to see but for now we will only use the "Run AppleScript" task to play the sound. We also could use the "Run Shell Script" task but AppleScript has some more convenience regarding reading / setting system settings like the current sound volume for example which we will utilise.

The green area contains the action settings and metadata.  Here we may change the color and image of the TouchBar action we are going to create.

The blue area is your workflow. You can drag/drop actions from the library to it to build up your program. We will only use one action ("Run AppleScript") but you can add up as many as you want.

So let's get started. Search for "AppleScript" inside the library and drag/drop it into the workflow area.

Step 4: Write the code

This is pretty straight-forward. Really the only thing we have to do is play the sound file. But what if your volume is very low?

So our logic has to be as follows

  • Check volume
    - If volume is lower than 50% set it to 50%
  • Play the previously downloaded sound file
on run
	if (get output volume of (get volume settings)) < 50 then
		set volume output volume 30
	end if
	do shell script "afplay ~/soundboard/winxperror.mp3"

end run

Now save your workflow and name it properly. You may also assign an icon for "touching it up" a little.

At the end, your workflow should look like this.

Step 5: Make your soundboard accessible from the TouchBar

You can either make the soundboard the default or modify your control strip to contain the quick actions shortcut.

1: Make it the default

If you want the sounds to display by default you have to modify your keyboard settings. Set the "TouchBar shows" dropdown to the "Quick Actions" option, and et voilà:

It wörkz!

2: Access sounds through the quick action shortcut

If you depend on your Fn-keys or just don't want these sounds to appear permanently, you can customise your control strip to contain the quick actions shortcut which "overlays" all of your quick actions.
Visit your system preferences and click 'Customise Control Strip' at the bottom of your keyboard settings and move the shortcut to where you want it to be.

The shortcut for expanding our quick actions / sounds

Now you should be able to open / close your soundboard. Enjoy!