Created
June 24, 2020 15:37
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const Blynk = require('blynk-library'); | |
const applescript = require('applescript'); | |
const AUTH = ''; | |
const blynk = new Blynk.Blynk(AUTH); | |
const volume = new blynk.VirtualPin(0) | |
const play = new blynk.VirtualPin(1) | |
const next = new blynk.VirtualPin(2) | |
const prev = new blynk.VirtualPin(3) | |
blynk.on('connect', function () { | |
volume.on('write', function (value) { | |
console.log(JSON.parse(value)) | |
const script = 'set volume output volume ' + JSON.parse(value); | |
applescript.execString(script, (err, rtn) => { | |
if (err) { | |
console.log(err) | |
// Something went wrong! | |
} | |
}); | |
}) | |
play.on('write', function (value) { | |
console.log(JSON.parse(value)) | |
const script = 'tell application "Spotify"\n' + | |
' playpause\n' + | |
' end tell'; | |
if (JSON.parse(value) === 1) | |
applescript.execString(script, (err, rtn) => { | |
if (err) { | |
console.log(err) | |
// Something went wrong! | |
} | |
}); | |
}) | |
next.on('write', function (value) { | |
console.log(JSON.parse(value)) | |
const script = 'tell application "Spotify"\n' + | |
' next track\n' + | |
' end tell'; | |
if (JSON.parse(value) === 1) | |
applescript.execString(script, (err, rtn) => { | |
if (err) { | |
console.log(err) | |
// Something went wrong! | |
} | |
}); | |
}) | |
prev.on('write', function (value) { | |
console.log(JSON.parse(value)) | |
const script = 'tell application "Spotify"\n' + | |
' previous track\n' + | |
' end tell'; | |
if (JSON.parse(value) === 1) | |
applescript.execString(script, (err, rtn) => { | |
if (err) { | |
console.log(err) | |
// Something went wrong! | |
} | |
}); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment