Display Spotify Song Info on Demand with Raycast

Display Spotify Song Info on Demand with Raycast

I recently switched to Raycast after hearing good things from friends. It's a tool that lets you control almost everything from one place. I wanted to use it to see what's playing on Spotify without shifting focus from my work.

Many apps and plugins pop up a toast notification with the song as it starts. That’s fine for some, but I needed something on demand. I wanted to know the song at any moment without interruptions or the hassle of opening Spotify.

I had a script from my journaling days in Day One where a simple shortcut like "song;" would print the current song’s name. I took this script and tweaked it to fit Raycast’s framework—a quiet, on-demand tool that fits into my workflow without noise.

Setting Up the Script

Here’s the setup:

  1. Create the Script Command: In Raycast, open the Extensions tab and add a new script command.
  1. Prepare the Script for Execution: Before using the script, make sure it’s executable. This is crucial for the script to run properly within Raycast. Open your terminal and enter:
chmod +x script_name
  1. Edit and Paste the AppleScript: Select AppleScript as the format. Insert this script:
#!/usr/bin/osascript

# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title What song is that?
# @raycast.mode inline
# @raycast.refreshTime 1h

# Optional parameters:
# @raycast.icon 🤖

# Documentation:
# @raycast.author Amit Jotwani
# @raycast.authorURL https://twitter.com/amit

if application "Spotify" is running then
    tell application "Spotify"
        if player state is playing then
            set currentTrack to current track
            set songName to name of currentTrack
            set songArtist to artist of currentTrack
            log "Listening to \"" & songName & "\" by " & songArtist
        else
            log "Spotify is not playing anything."
        end if
    end tell
else
    log "Spotify is not running."
end if

Raycast’s inline mode shows the song information in the command bar, updating only when you check (Raycast also supports a few more modes. You can learn more about them here).

No switching apps, no waiting for notifications. Just the song info, when you need it, without any fuss. It’s a small change, but it keeps the workflow smooth and focused.