Skip to content

Instantly share code, notes, and snippets.

@MarcoDVisser
Last active August 29, 2015 14:05
Show Gist options
  • Save MarcoDVisser/bc36e6923e82b2626dc2 to your computer and use it in GitHub Desktop.
Save MarcoDVisser/bc36e6923e82b2626dc2 to your computer and use it in GitHub Desktop.
Random File Rename for random wallpaper in Linux
#!/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
@MarcoDVisser
Copy link
Author

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