9pm: Be the DJ - Control Spotify from Your Terminal

Spotify? In the Terminal? This guide will introduce you to spotifyd, an open-source Spotify client for Unix-like systems. By setting it up, you'll be able to manage your music without interrupting your coding workflow. Let's get started.

What does this article replace?

This tutorial is a terminal-based alternative to managing your Spotify music through its desktop application or web player.

How long will it take to set up?

With a swift 15-minute setup, you'll be able to switch tracks and control your Spotify without ever having to leave your terminal.

3 out of 5 stars

Difficulty Rating:

Controlling your music streaming through terminal commands? You'll feel like you've snuck into the matrix, earning a 3/5 on the difficulty level scale.

Introduction

Spotifyd is an open-source Spotify client for Unix-like systems. It runs in the background as a daemon and allows you to control Spotify using terminal-based clients like spotify-tui. In this guide, we'll walk you through the process of installing and setting up spotifyd on macOS.

Prerequisites

  • A Spotify Premium account.

Step 1: Install Spotifyd

First, we'll install spotifyd using Homebrew. Open a Terminal window and type the following command:

brew install spotifyd

Homebrew will download and install spotifyd.

Step 2: Create a configuration file

Next, we'll create a configuration file for spotifyd that stores your Spotify login details and other settings. Use the following commands:

mkdir -p ~/.config/spotifyd
touch ~/.config/spotifyd/spotifyd.conf

This will create a new file at ~/.config/spotifyd/spotifyd.conf.

Step 3: Edit the configuration file

Now we'll edit the configuration file. You can use any text editor you like; in this example, we'll use nano:

nano ~/.config/spotifyd/spotifyd.conf

This will open the file in the nano text editor. Copy and paste the following into the file:

[global]
username = "<your-spotify-username>"
password = "<your-spotify-password>"
backend = "portaudio"
device_name = "spotifyd"
bitrate = 320

Replace <your-spotify-username> and <your-spotify-password> with your Spotify username and password.

Then press Ctrl+X to exit nano, press Y to confirm that you want to save the file, and then press Enter to confirm the filename.

Step 4: Run Spotifyd

You're now ready to run spotifyd! Type the following command in your Terminal window:

spotifyd

spotifyd will now run in the background. You should be able to see it as an available device in your Spotify client.

Step 5: Control Spotify from the Terminal

To control Spotify from the terminal, you can use a tool like spotify-tui. Here's how to install it:

brew install spotify-tui

Before running spotify-tui, make sure to set up the necessary environment variables. Follow the instructions in the spotify-tui readme for how to do this.

Once you've set up spotify-tui, you can run it with the following command:

spt

You can now control Spotify from the terminal!


Welcome to the new era of uninterrupted coding sessions. No more switching apps to control your music - your terminal has got it covered. Let your favourite tracks fuel your productivity as we move towards our midnight mark in this 24-article series.

Remember, the more you use these commands, the more they'll become second nature, bringing you closer to terminal mastery.