forked from dconnolly/chromecast-backgrounds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set.js
executable file
·38 lines (32 loc) · 1.52 KB
/
set.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/node
var getChromecastBackgrounds = require('./index');
var sys = require('sys')
var exec = require('child_process').exec;
var randomInt = function (low, high) {
return Math.floor(Math.random() * (high - low + 1) + low);
};
var getHome = function () {
return process.env.HOME || process.env.USERPROFILE;
};
var set = function (backgound) {
exec('wget "' + backgound['url'] + '" -O ' + getHome() + '/.wallpaper.jpg', function (error, stdout, stderr) {
console.log('done downloading wallpaper');
exec('gconftool -t string -s /desktop/gnome/background/picture_filename ' + getHome() + '/.wallpaper.jpg', function (error, stdout, stderr) {
console.log('done ubuntu');
});
exec('gsettings set org.gnome.desktop.background draw-background false && gsettings set org.gnome.desktop.background picture-uri file://'+getHome()+'/.wallpaper.jpg && gsettings set org.gnome.desktop.background draw-background true', function () {
console.log('done gnome 3');
});
exec('set-itemproperty -path "HKCU:Control Panel\\Desktop" -name wallpaper -value ' + getHome() + '/.wallpaper.jpg', function () {
console.log('done windows');
});
});
};
console.log('Remember add to the crontab');
console.log('0,30 * * * * ' + process.mainModule['filename']);
getChromecastBackgrounds().then(function (backgrounds) {
console.log('got ' + backgrounds.length + ' wallpapers');
var index = randomInt(0, backgrounds.length);
console.log('setting ' + index + ' one');
set(backgrounds[index]);
});