Skip to content

Instantly share code, notes, and snippets.

@nbqx
Created April 15, 2011 06:37
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbqx/921263 to your computer and use it in GitHub Desktop.
Save nbqx/921263 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
//http://vimeo.com/22429969
var fs = require('fs');
var spawn = require('child_process').spawn;
var cap = "/path/to/cap.jpg";
var glt = "/path/to/cap_glitch.jpg";
function changeDesktopPicture(){
var scrt = (function(){/*
tell application "Finder"
set org to POSIX file "/path/to/cap.jpg" as string
set desktop picture to file org
set pic to POSIX file "/path/to/cap_glitch.jpg" as string
set desktop picture to file pic
end tell
*/}).toString().replace(/^.*?\n/,'').replace(/\n.*?$/,'');
var doing = spawn('osascript',['-e',scrt]);
}
function glitch(f){
var v = (Math.random()>0.5)? 0.95 : Math.random()*1.5;
var file = f;
var buf = fs.readFileSync(file);
for(var i=0; i<buf.length; i++){
if(Math.random()>v){
if(buf[i]==18){
if(Math.random()>0.5){
buf[i] = Math.floor(Math.random()*10);
}else{
buf[i] = buf[i+1];
}
}
}
}
return buf
}
function capture(){
var cmd = spawn('screencapture',['-W','-tjpeg',cap]);
cmd.on('exit',function(){
var buf = glitch(cap);
fs.writeFile(glt,buf,function(err){
if(err) throw err;
changeDesktopPicture();
});
});
}
capture();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment