Created
July 1, 2012 04:29
-
-
Save jetpks/3026817 to your computer and use it in GitHub Desktop.
A node.js based gnome desktop background interval switcher.
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/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