PDA

View Full Version : Get current track from Spotify in Messages status(AppleScript)




pinyourwings22
Aug 6, 2012, 01:08 PM
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"
else
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
else
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 :)

Enjoy!



twd3lr
Aug 28, 2012, 12:40 PM
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?

pinyourwings22
Aug 29, 2012, 08:46 AM
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?

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!

stuckwithme247
Aug 29, 2012, 12:06 PM
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?

pinyourwings22
Aug 31, 2012, 07:39 AM
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?

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 :)

dabigdawg
Sep 12, 2012, 04:36 PM
Add this to the info.plist file, and the AppleScript shouldn't show up
in the Dock:

<key>NSUIElement</key>
<string>1</string>

charlieegan3
Mar 26, 2013, 07:13 AM
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"
else
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
else
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 :)

Enjoy!


Thank you oh so very much for this code :)