Skip to content

Instantly share code, notes, and snippets.

@dhbradshaw
Created April 25, 2021 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhbradshaw/335332d4cbc473e0c0b3c6750a07f947 to your computer and use it in GitHub Desktop.
Save dhbradshaw/335332d4cbc473e0c0b3c6750a07f947 to your computer and use it in GitHub Desktop.
Command to rotate to the next image on gnome desktop (if I save images I want to rotate through to Pictures/rotate_background)
#!/bin/bash
DIR="/home/doug/Pictures/rotate_background"
# Get full path
FULL_PATH=$(gsettings get org.gnome.desktop.background picture-uri)
# Clean off quotes.
FULL_PATH=$(echo $FULL_PATH | sed 's/.$//' | sed 's/^.//')
# Get base filename for comparison with ls output.
FILE_NAME=$(basename $FULL_PATH)
# Find the next file after this using grep.
NEXT_LINE=$(ls $DIR/* | grep $FILE_NAME -A1 | tail -n 1)
NEW_FULL_PATH="file://$NEXT_LINE"
# If we were already on the last line, we're stuck. So loop to the beginning.
if [ $NEW_FULL_PATH = $FULL_PATH ]
then
NEXT_LINE=$(ls $DIR/* | head -n 1)
fi
# Now set that image!
gsettings set org.gnome.desktop.background picture-uri "file://$NEXT_LINE"
@dhbradshaw
Copy link
Author

For some reason I like curating and then rotating through desktop backgrounds manually. I have this command connected to CTR-SHIFT-ALT-n, where n stands for next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment