Random generator to change my wallpaper
npm install desktop-eye-candyA program for setting randomized background wallpapers in a Linux or Windows desktop.
Each time this program executes, it will select a random image from one of its configured providers to use as a desktop background. When launched from a keyboard shortcut, it provides a very simple yet effective method for changing your wallpaper.
The following providers are supported:
* Google custom search
* Bing image search
* Pixabay image search
* Flickr (low-res requires no api key)
* Flickr hi-res
* Local json file of favorites' (See ~/desktop-eye-candy/favorites.json)
* Local directory handler
* Generic RSS feed handler
How to install this release.
If you've already installed an earlier version of desktop-eye-candy, you may use npm to upgrade the package.
```
npm upgrade -g desktop-eye-candy
> Note: upgrade will only update to the latest version of your currently installation major release. If you are at 3.0.0, it will not update to 4.x.
To upgrade to the very latest version...
``
npm uninstall -g desktop-eye-candy
followed by
npm install -g desktop-eye-candy
> Uninstallation does not remove the contents of ~/.desktop-eye-candy, so you configuration will be preserved.
Depending upon your version, an additional step is required.
Prior to 3.0.0, the app was launched from OS scripts ( e.g. wallpaper.sh and wallpaper.bat ). This has been changed to
invoke bin/wallpaper.js.
> Note, npm still creates a symbolic link to a 'wallpaper' command on that environment path; however, the command syntax is now different.
> 'wallpaper exec' is the new syntax. Please see Command Syntax for more details.
The existing configuration elements are no longer overwritten. Each time an update is applied, any new elements introduced into the source template lib/config.js file are added to your configuration (~/desktop-eye-candy/config.json) . Elements are never deleted or overwritten.
Copy your existing config.json file to ~/desktop-eye-candy/config.json before running npm -g update desktop-eye-candy. This manual step is only required one time since future updates will look for the configuration file in its new location.
If installing for the first time...
npm install -g desktop-eye-candy
`Specify imagePath
> For Windows, you MUST specify the drive letter too. 'Drive 'C:' is the default post-installation added automatically.
e.g.
`
"imagePathDirectory" : "c:/tmp",
`
Post Install/Upgrade Setup
After the package is installed or updated, a script runs to complete the post-installation setup.
* Create an app home directory under ~/.desktop-eye-candy
* Install ~/.desktop-eye-candy/images - i.e. the default local file store for the localFS provider)
* Install ~/.desktop-eye-candy/favorites.json containing favorite URLs for the favorites provider
Create API keys
Most of the supported providers ( Bing, Google Custom Search, Flickr HiRes and Pixabay ) require an authorized API key. Moreover, for Pixabay, one must send an email requesting access to high-resolution images as discussed in their API docs. The Flickr provider requires no API key; however, it is disabled by default.Configure
Configure one of the supported providers by editing '~/.desktop-eye-candy/config.json'. You will want to install API keys and search terms.Command Syntax
To generate a random image and set it to the desktop backgroud, run this command.
`
wallpaper exec
`The following options are supported.
| command | Notes |
| ----------- | ----- |
| wallpaper -h | Help doc |
| wallpaper exec | Create a random image and set it on the desktop background. The image should be immediately visible |
| wallpaper gen | Create a new random image only. The /tmp/wallpaper.jps and /tmp/wallpaper.json files are created |
| wallpaper set | Set the last desktop background using the last created image.
| wallpaper get | Return the JSON string for /tmp/wallpaper.json |
| wallpaper fav | Create an entry in the ~/.desktop-eye-candy/favorites folder for the currently selected desktop image
> Note, 'wallpaper exec' and 'wallpaper gen && wallpaper set' are functionally equivalent.
Testing Details
The following platforms have been tested thus far.| OS | Notes |
| ------------- | :------|
| Ubuntu 14.04 | None |
| Ubuntu 16.04 | After installation and configuration, logout and log back in if using keyboard shortcut.|
| Ubuntu 17.10 | None |
| Windows 10 Home Edition (1709) | None|
Dependencies
Ensure the following dependencies are installed:$3
`
$ sudo apt-get install nitrogen
`
* nitrogen - set the desktop background to the downloaded image$3
* PowershellNode.js
Install Node.js$3
* Install Node.js
* Export a NODE_HOME variable
`
export NODE_HOME=/path/to/Node.js
`
Note: The simplest approach is to add NODE_HOME to /etc/environment.e.g.
/etc/environment
`
NODE_HOME=/home/user/dev/node-v9.7.1-linux-x64
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
user@zfs-VirtualBox:~/dev/git/usawco$ `$3
* Create NODE_HOME environment variable
* Add %NODE_HOME% to the PATH variable> Or use the Node.js .msi installer
Usage Notes
The same two files are created in the configured imagePathDirectory each time 'wallpaper exec' or 'wallpaper gen' is run.e.g.
`
$ ls -l /tmp/wallpaper*
-rw-rw-r-- 1 user user 557659 Mar 4 2015 /tmp/wallpaper.jpg
-rw-rw-r-- 1 user user 185 Mar 5 09:05 /tmp/wallpaper.json
$
`Image Provider Notes
This section provides more information regarding the delivered set of image providers.
Desktop-eye-candy randomly selects images from several sources. Each source is described as a 'provider'. The rest of this section describes information for each of the available providers.
$3
This was originally described as a 'favorites' provider feature before 4.0.x; however, it is now renamed as the 'Local file system provider'. This provider contains a list of local
directory paths containing image files. By default, there always exists one implicitly defined directory path to ~/.desktop-eye-candy/images$3
This provider contains a list of URLs stored in a JSON formatted file in the app's home directory. New entries may be added to the favorites via the 'fav'
command. It's purpose is to bookmark a set of the random entries deemed 'favorites'. The file may be found here: ~/.desktop-eye-candy/favorites.json$3
$3
$3
$3
$3
$3
This provider will accept an array of URLs that return raw RSS feeds in XML format. desktop-eye-candy uses xml2js to parse the XML response into a JSON object.
Two approaches are used to gather images based upon how the handler is configured.
If a 'location' is provided, the handler will search all elements of the RSS response anywhere they exist under each 'item' element looking for a 'location' name match. If no URL is found, the item element is dumped when trace logging is enabled.
If 'searchLinks' is true, each HTML response to the URL defined in each item's 'link' element is examined looking for '
' tags.
Configuration
Modify the ~/.desktop-eye-candy/config.json file
* Verify the imagePathDirectory setting. (Windows must include the drive letter. e.g. C:/tmp )
* Insert your own API keys for Bing, Google Custom Search, Flickr API or Pixabay
* Modify the search terms for each provider. (There is no GUI config at this time.)
* Change the provider's 'enabled' key value from false to true.
Troubleshooting
Node JS logging
Node.js trace logging is available via NODE_DEBUG env variable.$3
`
$ NODE_DEBUG=wallpaper wallpaper exec
Resolving configuration from /home/user/.desktop-eye-candy/config.json
WALLPAPER 12183: Loading Favorites handler config
WALLPAPER 12183: {"enabled":false,"desc":"List of favorite images","feeds":["favorites/"]}
WALLPAPER 12183: Loading flickr config
WALLPAPER 12183: {"enabled":false,"terms":["mountains","puppies"],"desc":"Flickr low resolution images (No key required)"}
WALLPAPER 12183: Loading Google config
.
.
.
Expires: Wed, 04 Apr 2018 14:05:08 GMT
Connection: close
Content-Type: image/jpeg---response end---
200 OK
Length: 557659 (545K) [image/jpeg]
Saving to: ‘/tmp/wallpaper.jpg’
100%[==================================================================================================>] 557,659 984KB/s in 0.6s
Closed fd 4
2018-03-05 09:05:10 (984 KB/s) - ‘/tmp/wallpaper.jpg’ saved [557659/557659]
Setting wallpaper
$
`$3
`
C:\>set NODE_DEBUG=wallpaperC:\>wallpaper
Resolving configuration from C:\Users\user\.desktop-eye-candy\config.json
WALLPAPER 6824: Loading Favorites handler config
WALLPAPER 6824: {"enabled":true,"desc":"List of favorite images","feeds":["favorites/"]}
WALLPAPER 6824: Loading flickr config
.
.
.
`Keyboard Shortcut
Add this program to a keyboard shortcut for maximum ease of use. Linux
I suggest using gnome-terminal for the terminal popup, so you can monitor its progress since some images may take a few seconds to download.
e.g. I've created a bash profile called 'login' in the example below that sets the custom green foreground color.
`
$ gnome-terminal --window-with-profile=login -e /home/user/desktop-eye-candy.sh
`
`
user@user-VirtualBox:~/dev/git/usawco/wallpaper$ cat ~/desktop-eye-candy.sh
#!/bin/bash
NODE_DEBUG=wallpaper wallpaper exec
`
Windows
Create a Shortcut and assign a keyboard mnemonic
`
Start in: %APPDATA%\npm
Target: C:\WINDOWS\system32\cmd.exe /c wallpaper exec
`dev notes
Adding another handler
wallpaper.js acts as a controller for a set of handlers (e.g. bing, pixabay, google custom search, flickr).$3
Use one of the existing handlers as a guide. Be sure to export an 'exec' function in the new handler's module that returns a Promise.$3
Add the handler to the list of promises defined in wallpaper-controller.js.
`js
var entry = null;
let theHandlers = [];
if ( config.providers.favorites.enabled) theHandlers.push(favorites);
if ( config.providers.localFS.enabled) theHandlers.push(localFS);
if ( config.providers.bing.enabled) theHandlers.push(bing);
if ( config.providers.google.enabled) theHandlers.push(googs);
.
.
.
// new handler goes here...
];
`
$3
Your config elements may be different for your handler.
For example, here is the bing entry. You would add a new entry with for your handler. In this example, I'm returning images with the 'nature' search term. (See config.js for more details.)
`js
"bing" : {
"enabled" : true,
"key" : "xxxxxxxxxxx",
"terms" : [ "nature" ],
"width" : 1920,
"height" : 1080
},
``