Skip to content

Instantly share code, notes, and snippets.

@jetpks
Created July 1, 2012 04:29
Show Gist options
  • Select an option

  • Save jetpks/3026817 to your computer and use it in GitHub Desktop.

Select an option

Save jetpks/3026817 to your computer and use it in GitHub Desktop.
A node.js based gnome desktop background interval switcher.
#!/usr/local/bin/node
(function() {
"use strict";
// The purpose of this script is to switch the gnome background every x
// minutes.
var exec = require('child_process').exec
, fs = require('fs')
, interval = 0
, imgDir = ''
, loop
;
function usage() {
console.log("./switcher.js <interval in minutes> <full path to images directory>\n Example: ./switcher.js 15 /home/eric/Pictures/wallpaper_general/");
}
function init() {
if(process.argv.length != 4) {
console.log('argv length:', process.argv.length);
usage();
process.exit(1);
}
interval = parseInt(process.argv[2]);
imgDir = process.argv[3];
selectRandom();
loop = setInterval(selectRandom, (interval * 1000)*60);
}
function selectRandom() {
fs.readdir(imgDir, function(err, files) {
display(files[parseInt(Math.random() * files.length - 1)]);
});
}
function display(file) {
exec('/usr/bin/gsettings set org.gnome.desktop.background picture-uri file://' + imgDir + '/' + file, function (err, stdout, stderr) {
if(err) {
console.error('Error: ', err);
}
});
}
init();
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment