Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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