Get current track from Spotify in Messages status(AppleScript)

Discussion in 'Mac Programming' started by pinyourwings22, Aug 6, 2012.

  1. macrumors member

    As a newer user to the Messages application on Mountain Lion, I wanted to get the current Spotify track to display on my status(as opposed to iTunes), but couldn't find any readily available code. Once I got it working, I figured there would be others like me so I wanted to provide my code :)

    on idle
    	tell application "Spotify"
    		set theTrack to current track
    		set theArtist to artist of theTrack
    		set theName to name of theTrack
    		if player state is playing then
    			set playStatus to "playing"
    			set playStatus to "notPlaying"
    		end if
    	end tell
    	tell application "Messages"
    		if status is available then
    			if playStatus is "playing" then
    				if (theArtist as string) is not "Spotify" then
    					set status message to ("♫ Playing in Spotify: " & (theArtist as string) & " - " & (theName as string))
    				end if
    				set status message to "Available"
    			end if
    		end if
    	end tell
    	return 5
    end idle
    Basically, it checks every 5 seconds to see which track is playing and posts it to your available status on Messages. If Spotify is paused, it changes it back to "Available".

    If this is not the correct forum to post this, please kindly redirect me :)

  2. macrumors newbie

    I cannot get this to work, but then again I am a complete novice when it comes to Applescript. I would just like to be able to get this script to work. Help?
  3. macrumors member

    Yeah it's pretty simple, just open up AppleScript Editor, paste this code in, go to File > Export... File Format: Application, Options: Stay open after run handler.

    Now you can just open the application you created. When running Spotify and Messages, the status will update with your current song.

    hope this helps!
  4. macrumors regular

    Awesome script. Thanks a lot for posting this, I've always wanted to be able to do this. Question though, do you think it would be possible to make this selectable from the status menu in the Messages buddy list and not have to have a dock icon open?
  5. macrumors member

    Not really sure, to be quite honest I'm a pretty new to AppleScript. My guess is that you would have to make it run in the background somehow or integrate directly with the Messages application(which I have no clue if that's even possible).

    I'll take a look into it, but please post the solution if you have any luck finding one :)
  6. macrumors newbie

    Add this to the info.plist file, and the AppleScript shouldn't show up
    in the Dock:

  7. macrumors 68020



    Thank you oh so very much for this code :)

Share This Page