Not just Spotify—this method works for any macOS app.

AppleScript is a powerful automation/scripting tool built right in the core of macOS. You can think of it as PowerShell on Windows. With AppleScript you can control the operating system, apps, and perform various tasks within each app. Notably, the combination of AppleScript with apps such as Hammerspoon, Keyboard Maestro, and Alfred can boost your productivity in leaps and bounds. In this article, I’m going to show how AppleScript can be used to control Spotify.

1. Commands that can be performed in macOS apps

Each macOS app has a list of commands that can be performed programmatically (via AppleScript). This list is an XML file with the AppleScript definitions. For Spotify it is:

/Applications/Spotify.app/Contents/Resources/Spotify.sdef

Notice that the extension is *.sdef . An SDEF file is actually an XML file written for AppleScript and which contains a dictionary of terms, which includes classes (nouns), properties (adjectives), commands (verbs), and parameters (adverbs).

You can think of SDEF files as the “APIs” of macOS programs: an SDEF file stores the terminology used to communicate with the underlying program being controlled by AppleScript.

If you open Spotify’s SDEF file and search for command , here’s what you’ll get:

Spotify’s commands in its SDEF file

As we can see, the following actions can be done:

Unfortunately, liking or starrting 💚 a track is not available, which is a real bummer. I really hope Spotify add this functionality so we don’t have to switch to the app to like the currently playing song.

2. Controlling Spotify via AppleScript

To write our AppleScript code, we need to open Script Editor, an app that’s shipped with macOS. You can search for it in Spotlight. Create a new AppleScript document. Now you can start coding.

AppleScript’s syntax is straightforward and simple. For example, if you want to pause Spotify, here’s what you do: