Get current app information from App.sdef

134 Views Asked by At

I'm trying to access information about the current status of a Mac app like I would with dbus on linux.

The app I'm trying to do this with is Spotify. I searched through the package contents and I found there was a Spotify.sdef file in the /Resources directory. I did some research on these "Script Definitions" and I think there's a way I can access the data described in the Spotify.sdef file (ie. the title and artist info). I may be completely wrong as I have zero experience with Cocoa development.

I'd be very grateful if someone could point me in the right direction on accessing the data I believe to be accessible from "Script Definition" file in an application's package contents. My final goal is to be able to see what song is currently playing in Spotify through a simple terminal command.

1

There are 1 best solutions below

0
On BEST ANSWER

Have you seen Spotify's AppleScript docs? This small modification of the example should do what you're looking for:

#!/usr/bin/env osascript

set currentlyPlayingTrack to getCurrentlyPlayingTrack()
log currentlyPlayingTrack

on getCurrentlyPlayingTrack()
    tell application "Spotify"
        set currentArtist to artist of current track as string
        set currentTrack to name of current track as string
        return currentArtist & " - " & currentTrack
    end tell
end getCurrentlyPlayingTrack