Created
May 1, 2014 08:23
-
-
Save nbqx/11447006 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var Readable = require('stream').Readable, | |
exec = require('child_process').exec; | |
var clc = require('cli-color'), | |
csv2 = require('csv2'), | |
through2 = require('through2'); | |
function getVolume(){ | |
var rs = new Readable; | |
var cmd = 'osascript -e "get volume settings"'; | |
rs._read = function(){ | |
exec(cmd,function(err,stdout,stderr){ | |
if(err) return rs.emit('error',err); | |
if(stderr) return rs.emit('error',stderr); | |
rs.push(stdout); | |
}); | |
}; | |
return rs | |
}; | |
function valueParser(){ | |
function _split(str){ | |
return parseInt(str.split(/:/)[1]); | |
}; | |
return through2({objectMode: true}, function(chunk,enc,next){ | |
this.push({ | |
output: _split(chunk[0]) | |
}); | |
next(); | |
}); | |
}; | |
function show(data){ | |
var c = (function(n){ | |
var ret = []; | |
for(var i=0; i<n; i++){ ret.push("\uD83C\uDE50"); } | |
return ret.join('') | |
})(Math.round(data.output*0.1)); | |
var out = [ | |
clc.reset, | |
"\uD83C\uDFA7 ", | |
c | |
].join(''); | |
console.log(out); | |
}; | |
var volvis = getVolume().pipe(csv2()).pipe(valueParser()); | |
volvis.on('data',show); | |
process.once('SIGINT',function(sig){ | |
volvis.push(null); | |
process.exit(0); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment