Skip to content

Instantly share code, notes, and snippets.

@qrohlf
Created June 16, 2015 14:31
Show Gist options
  • Save qrohlf/66537a22ea0a00b1640b to your computer and use it in GitHub Desktop.
Save qrohlf/66537a22ea0a00b1640b to your computer and use it in GitHub Desktop.
Trianglify Wallpaper set
var Trianglify = require('trianglify');
var fs = require('fs');
var exec = require('child_process').exec;
// Generate a pattern and then grab the PNG data uri
var pngURI = Trianglify({
width: 1440,
height: 900,
cell_size: Math.random()*200 + 30,
x_colors: 'random',
variance: Math.random(),
}).png();
// Strip off the uri part of the data uri, leaving the data
var data = pngURI.substr(pngURI.indexOf('base64') + 7);
// Decode the base64 encoded blob into a buffer
var buffer = new Buffer(data, 'base64');
// Save the buffer to a file
fs.writeFileSync('/tmp/wallpaper.png', buffer);
// Change the wallpaper
exec("osascript -e 'tell application \"Finder\" to set desktop picture to POSIX file \"/tmp/wallpaper.png\"'")
osascript -e 'tell application "Finder" to set desktop picture to POSIX file "/Users/qrohlf/Projects/trianglify/examples/wallpaper.png"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment