Created
April 15, 2011 06:37
-
-
Save nbqx/921263 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
#!/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