Stumbling on a geektool script a while ago encouraged me to tinker with Spotify’s applescript interface - where I thought I might find some options that would have been useful to push Spotify Menubar further (for times when I might want to change it). Here is what Spotify’s applescript suite offers:
image data n : Image data in TIFF format.
sound volume (integer) : The sound output volume (0 = min, 100 = max).
player state (stopped/playing/paused, r/o) : Is Spotify stopped, paused, or playing?
player position (real) : The Player’s position within the currently playing track in seconds.
next track : Skip to the next track.
previous track : Skip to the previous track.
playpause : Toggle play/pause.
pause : Pause playback.
play : Resume playback.
current track (track, r/o) : The currently playing track.
Properties of the current track
artist (text, r/o) : The artist of the track.
album (text, r/o) : The album of the track.
disc number (integer, r/o) : The length of the track in seconds.
duration (integer, r/o) : The length of the track in seconds.
played count (integer, r/o) : The number of times this track has been played.
track number (integer, r/o) : The index of the track in its album.
starred (boolean, r/o) : Is the track starred?
popularity (integer, r/o) : How popular is this track? 0-100
id (text, r/o) : The ID of the item.
name (text, r/o) : The name of the track.
artwork (image data, r/o) : The track’s album cover.
album artist (text, r/o) : The album artist of the track.
spotify url (text) : The URL of the track.
Most, if not all, of the info here is useful, though I would like to see the ability to write the starred status of a track (r/o means read only, afaik).
With NSApplescript it is easy to take advantage of the applescript properties and use them in a cocoa-based app. Though what is offered is mostly read only, except player position and volume. A simple implementation to illustrate this (by getting the currently playing track name):
NSString *scriptString = @”tell application “Spotify”\n set output to name of current track\n end tell”;
NSAppleScript *script = [[NSAppleScript alloc] initWithSource: scriptString];
NSAppleEventDescriptor *returnData = [script executeAndReturnError:nil];
NSLog([output stringValue]);
Though in hindsight I would have enjoyed playing with this, I only needed the global hotkeys and not the information. After playing about there’s nothing I would really change in Spotify Menubar. Considering Bowtie, Airfoil and Take Five will be working with Spotify, I will probably be using them if I use Spotify.
Update:
I was asked how to write the image data to a file. This is how I might go about it:
NSString *scriptString = @”tell application "Spotify"\n set image_data to artwork of current track\n end tell\n image_data”;
NSAppleScript *script = [[NSAppleScript alloc] initWithSource: scriptString];
NSAppleEventDescriptor *returnData = [script executeAndReturnError: nil];
[[returnData data] writeToFile:@”/Users/<Your Username>/Desktop/artwork.tiff” atomically:NO];
Replacing <Your Username> with your actual username.