off topic Spotify Applescript

tkimpton
Valued Contributor II

I got a bit bored on leave and created this. Replace the http url to your spotify playlist and save it as a run only application. With this and setting my mac to auto power on after a power outage i can automatically have tubea playing when i get in by flicking the switch :)

http://www.belkin.com/uk/conserve/switch/

Unfortunately had to killall Spotify to start with so that it wouldnt keep playing the same song along with some trickery with the volume!

try
-- Kill Spotify
do shell script "killall Spotify"
end try

-- Pause 5 seconds
delay 5

try
tell application "Spotify"
    activate
end tell

    -- Make sure shuffle & repeat is on
    tell application "Spotify"
        if shuffling is false then
            set shuffling to true
            if repeating is false then
                set repeating to true
            end if
        end if
    end tell

    delay 1

    -- Open the playlist via a web browser. Customize this your own playlist.
    open location "http://open.spotify.com/user/kdog79/playlist/2489FoNrgU1e4ItOm4ubOw"

    tell application "Spotify"
        set sound volume to 0
    end tell

    delay 5
    tell application "Spotify"
        next track
    end tell

    tell application "Spotify"
        next track
        delay 2
        set sound volume to 100
    end tell
end try

Very useful if someone keeps playing dreadful hotchip in the office!

5 REPLIES 5

tkimpton
Valued Contributor II

hmm time to rid the world of Massive Attack and Hot Chip with a launch agent (watch paths obviously) and this script. My App is called KMix :)

#!/bin/bash
# Process Check to see if Spotify is running
if ps aux | grep -v grep | grep Spotify.app
then

# Specify to run it as an OS applesctipt specifying it ends at EOT
/usr/bin/osascript <<EOT

# Get the current track
tell application "Spotify"
set theTitle to name of the current track
set check to artist of current track

# If the track is Lebanese Blonde then skip it
if theTitle is "Lebanese Blonde" then
play (next track)
end if

# If its crap Hot Chip then skip it
if check is "Hot Chip" then
do shell script "open /Applications/KMix.app"
end if

# If its Massive attack then skip it
if check is "Massive Attack" then
do shell script "open /Applications/KMix.app"
end if

# If its that annoying track skip it
if theTitle is "Testify" then
do shell script "open /Applications/KMix.app"
end if
end tell
EOT
fi
exit 0

tkimpton
Valued Contributor II

One annoying thing is that different departments keep turning down the Spotify volume itself using our ipod remoteless app instead of using our other volume control app iRule.

Time to fix that ;)

with a launch daemon with watchpath to the users spotify cache

and this bash script actually an applescript written in bash... yes that right peeps use this example if you need to run an applescript as a login hook but never worked out how

#!/bin/bash
# Process Check to see if Spotify is running
if ps aux | grep -v grep | grep Spotify.app
then

# Specify to run it as an OS applesctipt specifying it ends at EOT
/usr/bin/osascript <<EOT

# Pause 15 seconds
delay 15

# Set the variable volcheck to get the current sound volume of Spotify
tell application "Spotify"
set volcheck to get sound volume

# If the volume is not up full then turn it up!
if volcheck is not 100 then
set sound volume to 100
end if
end tell
EOT
fi
exit 0

tkimpton
Valued Contributor II

Does anyone know how i can just check the process Spotify?

There is a constant SpotifyWebHelper process running causing it not to be very clean, in otherwords if you quit spotify it opens up again to run the script because of the blasted SpotifyWebHelper.

Can anyone tell me how to exclude this?

tkimpton
Valued Contributor II

changed the scripts above to do a ps aux | grep -v grep | grep Spotify.app so that it wouldn't grep the SpotifyWebHelper ;)

tkimpton
Valued Contributor II

changed my script due to it failing because of the recent web player.

What i did this time is reference a track from a playlist i found on Spotify and stored it in /Users/Shared/tunes.rtf created using vi

(right click track and Copy Spotify URI)

This means when i want to change the music playlist i just change the file contents in /Users/Shared/tunes.rtf

this is what im using at the moment which has some good morning track on there

spotify:user:1137064509:playlist:6FeclgYp45QjvvIEH7f4DS

The App then references this and plays it, skipping to the next track so that it doesn't start with the same one all the time

Have the app open at login

Set the mac to autostartup and login in automatically :)

Got moaned at a bit for blocking tracks :(

try
    -- Kill Spotify
    do shell script "killall Spotify"

    -- Pause 5 seconds
    delay 5

    -- read the reference file
    set tunes to do shell script "cat /Users/Shared/tunes.rtf"


    -- Make sure shuffle & repeat is on
    tell application "Spotify"
        if shuffling is false then
            set shuffling to true
            if repeating is false then
                set repeating to true
            end if
        end if
    end tell

    delay 1


    tell application "Spotify"
        activate
        set sound volume to 0
        play track tunes
        next track
        delay 6
        set sound volume to 100
    end tell


    -- Bring Spotify to the front

    set appName to "spotify"
    set startIt to false
    tell application "System Events"
        if not (exists process appName) then
            set startIt to true
        else if frontmost of process appName then
            set visible of process appName to false
        else
            set frontmost of process appName to true
        end if
    end tell
    if startIt then
        tell application appName to activate
    end if

end try