Skip to content

Instantly share code, notes, and snippets.

@hasanbasri1993
Created June 24, 2020 15:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hasanbasri1993/e07056894626e7d4e19e62b8fdd3265d to your computer and use it in GitHub Desktop.
#!/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