qxnmlw
Last Updated: February 25, 2016
·
209
· fnurl

JavaScript automator workflow to controll Spotify via Launchbar

I just wrote this snippet to control Spotify using an automator workflow written in JavaScript!

function run(input, parameters) {
    // commands for play/pause
    var playpauseCommands = new Array("play", "pause", "stop");

    // commands for next track
    var nextCommands = new Array("next", "n");

    // commands for previous track
    var prevCommands = new Array("previous", "prev", "p");

    var inputString = input[0].toLowerCase();
    var Spotify = Application('com.spotify.client');
    if(playpauseCommands.indexOf(inputString) != -1) {
        Spotify.playpause();
    } else if(nextCommands.indexOf(inputString) != -1) {
        Spotify.nextTrack();
    } else if(prevCommands.indexOf(inputString) != -1) {
        Spotify.previousTrack();
    }
    //return input;
}