You are not logged in.
This is a simple wallpaper rotater that I wrote. This was prior to me stumbling across @damo's rather elegant solution and was based on the concepts of @corenominal's bash script that just wouldn't work for me. Being that I am not the best bash scripter in the world, I chose to use python. As you can see from the to-do notes, I really want it to be a more robust and transparent tool. Perhaps one day, I will get around to finishing it out. I choose to hook this into my conky and run it once every half hour via this command:
${execpi 1800 rotate-wallpaper}
As you can see the command assumes that a script called rotate-wallpaper is somewhere in your path, as I did not hardcode the link to it.
And the script itself:
#! /usr/bin/env python
## To-Do's:
## Accept arbitray path to images
## Accept .jpg, .png and possibly .svg extensions
## Allow for more than one command to set bg.
## Examples: hsetroot, nitrogen, feh, possibly pcmanfm
## Look into separate wallpapers per display
import os
import random
import sys
my_path="/home/tknomanzr/remote/Shared_Pictures/walls/"
my_extension=[".jpg",".png"]
def directory(path, extension):
list_dir = []
list_dir = os.listdir(my_path)
count = 0
for file in list_dir:
for i in range(len(extension)):
if file.endswith(extension[i]):
count += 1
if not list_dir:
print "No useable image files found."
return (list_dir, count)
def background(bg):
cmd = "feh --bg-scale " + bg
os.system(cmd)
return
list_dir, count = directory (my_path, my_extension)
file_number = random.randint(0, count-1)
bg_name = my_path + list_dir[file_number]
background(bg_name)
Offline
Sounds perfect for a giant collection of Google satellite wallpapers: gist
red
Knowledge Ferret
Offline
@tknomanzr:
There is a bug in the script:
1. Create a new directory DIR
2. create 2 files in that dir, in the order specified here:
touch a.what
touch b.png
3. Now run your script (after changing my_path to the DIR you created)
Your script will try to set a.what as the wallpaper!
xaos52, 'The unofficial, self-assigned bunsenlabs scripts Quality Assurance Officer'
Offline
@hhh,
Thanks for making that title official for a very short time, but 'The Good Doctor' makes me proud too.
Offline
Ok. Ill check the logic on it. I intend to flesh it out more at some point. Actually, the more I think on it, the more I realize actually relying on a file extension to be present is somewhat foolish. I am going to give some thought into parsing the output of the file command or see if python has something similar to that command to test the file type.
Offline
@hhh,
Thanks for making that title official for a very short time, but 'The Good Doctor' makes me proud too.
Sorry, that was me
Which title would you prefer?
@tknomanzr -- sorry for the OT
Offline
'The Good Doctor' is OK. Thanks.
I saw hhh on-line when I logged in, so I thought he set the title.
Offline
Looks like pyython has a built in module to handle this. I will try to work on this some soon. I was using this with a collection of Hubble telescope images for the longest.
Offline
@tknomanzr:
Here is something I quickly threw together, that seems to work:
[== Undefined ==]
#! /usr/bin/env python
## To-Do's:
## Accept arbitray path to images
## Accept .jpg, .png and possibly .svg extensions
## Allow for more than one command to set bg.
## Examples: hsetroot, nitrogen, feh, possibly pcmanfm
## Look into separate wallpapers per display
import os
import random
import sys
MY_PATH="/home/me/tmp/today"
MY_EXTENSIONS=[".jpg",".png"]
def select_one_wallpaper(candidates):
try:
# select one wall from the candidates
return random.choice(candidates)
except IndexError:
print 'No candidate wallpapers found in directory %s.\n' % (MY_PATH,)
sys.exit(1)
def set_background(wallpaper):
cmd = "feh --wall-scale %s" % (os.path.join(MY_PATH, wallpaper))
retval = os.system(cmd)
if retval:
print 'Setting the wallpaper returned an error.'
if __name__ == '__main__':
candidates = [ x for x in os.listdir(MY_PATH) if os.path.splitext(x)[1].lower() in MY_EXTENSIONS ]
wallpaper = select_one_wallpaper(candidates)
set_background(wallpaper)
Last edited by xaos52 (2015-10-04 16:52:54)
Offline
@tknomanzr:
Well your script works OK if the directory contains nothing but files with extensions .jpg or .png.
BTW: I feel 'rotate' is a misnomer for the script, since it randomly selects one from a collection. Perhaps something like 'set-random-wallpaper' is better?
Last edited by xaos52 (2015-10-04 17:03:09)
Offline
Any good isImage functions for bash? What I have is usually the "file" command and/or actually doing something with a file
img2txt some.png || echo "probably not an image"
or the somehow ugly grep (hasAudio) < which should fail in a number of imaginary situations, but actually holds in practice
if [ -f "$expanded" ] && mediainfo "$expanded" | egrep -qi 'audio'; then
# stuff
fi
Last edited by brontosaurusrex (2015-10-04 18:08:40)
Offline
Look at the `file` command. Test the if the return is `image`
man file
Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt «» BunsenLabs on DeviantArt
Offline
The jessie file seems really good and I'am aware of it, see my first line
Offline
I found this Python Module that I was thinking about using.
Offline