24 Oct

Automatically launch Spotify playlist and start playing on shuffle

At work, we needed a quick and dirty way to start playing our office playlist. Because there were three people, it needed to be as simple as possible. So, I ended up with the following shortcut assigned to a dedicated button on my Logitech G13 with the joystick mapped to volume up/down and mute. Works a treat.

Here’s how:

  • Make sure you are targeting the right page, tick on “enable cjs for this host” and paste the following code (remember to change !!!yourplaylistid!!! to your… you guessed it!)
$("document").ready(function() {
  if(window.location.href.indexOf("!!!yourplaylistid!!!") > -1) { // change the ID to restrict the script to only run on the playlist you choose
    setTimeout(function() { // wait 5 seconds to finish page load and simulate clicking on the shuffle button
      $('.spoticon-shuffle-16').trigger('click');
    },5000);
    setTimeout(function() { // 2 seconds later, simulate pressing the next button to play a 'random' song
      $('.spoticon-skip-forward-16').trigger('click');
    },7000);
  }
});

From now on, every time you launch your SuperAwesomePlaylist shortcut it will go right into your chosen playlist, start playing on shuffle and skip to the next song, just so it doesn’t start off with playing the same song on each launch!

And now that you have your shortcut file, you can launch it in interesting ways:

  • Copy it to Windows start-up so everytime your PC loads it starts playing your music
  • Using the Bluetooth Proximity Lock app, start your playlist as soon as your phone connects