Last active
August 29, 2015 14:05
-
-
Save MarcoDVisser/bc36e6923e82b2626dc2 to your computer and use it in GitHub Desktop.
Random File Rename for random wallpaper in Linux
This file contains 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
#!/bin/bash | |
# Seed random generator | |
RANDOM=$$$(date +%s) | |
# read all jpg files in folder | |
# replace the $( ) with '' for older versions | |
# creates an array of all the files in ~/bin/images/wp | |
FILES=(~/bin/images/wp/*) | |
NFILES="${#FILES[@]}" #determines the length of the FILES array | |
randomid=$((RANDOM % NFILES)) #$RANDOM selects a random number between 0 and $NFILES | |
F="${FILES[$randomid]}" #the random file | |
echo "Processing $F ..." | |
cp "$F" ~/bin/images/wp/tmp.jpg #does the actual moving | |
exit 0 | |
And if you want to avoid having to explicitly set the wallpaper to tmp.jpg you could look here: http://stackoverflow.com/questions/5550895/shell-script-changing-desktop-wallpaper
Thanks, Dason. The script was more about teaching myself more about BASH scripting than anything else. This generic code works on all platforms, in a personal script I set my wp specific to the machine I'm on. In this case it's a machine running i3, and I use something like the above. However setting tmp.jpg as your back ground in works on all systems right?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You don't need to muck around with using the date to generate random numbers in BASH - http://tldp.org/LDP/abs/html/randomvar.html