Skip to content

Instantly share code, notes, and snippets.

@eternal-sorrow
Created April 30, 2020 16:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save eternal-sorrow/09f278aabbbe5cd81589de00c9fb018c to your computer and use it in GitHub Desktop.
Save eternal-sorrow/09f278aabbbe5cd81589de00c9fb018c to your computer and use it in GitHub Desktop.
Generate auto changing wallpater XML file for GNOME
#!/bin/bash
#finishing script function
die()
{
if ! [ -z $2 ]
then
rm -f $2
fi
echo "Exiting..."
exit $1
}
# Usage: bgxml-gen [<path> [<duration in minutes> [<animation duration in seconds>]]]
V=$1
if [ -z $V ]
then
V=$PWD
elif ! [ -d $V ]
then
echo "Error: $V: Not a directory"
die 1
fi
V=$(realpath $V)
TIME=$2
if [ -z $TIME ]
then
TIME=15
fi
echo "The time was set to $TIME minutes."
TIME=$(($TIME*60))
ANIMATION=$3
if [ -z $ANIMATION ]
then
ANIMATION=0
fi
echo "The animation time was set to $ANIMATION seconds."
FILES=.file-$RANDOM
echo "The temp file is $FILES."
echo "Searching images in $V."
#searching for files
for EXT in jpg jpeg png gif svg
do
find "$V" -iname "*.$EXT" | sort -d >> $FILES
done
LINES=$(wc -l < "$FILES")
if [ $LINES -eq 0 ]
then
echo "No images was found in the directory."
die 2 $FILES
fi
BACK="$HOME/.config/background.xml"
echo "The name of the xml file is $BACK."
echo "Creating the xml file."
echo "<!-- GENERATED WITH XML BACKGROUND CREATOR SCRIPT (bgxml-gen) -->" > "$BACK"
echo "<background>
<starttime>
<year>2009</year>
<month>08</month>
<day>04</day>
<hour>00</hour>
<minute>00</minute>
<second>00</second>
</starttime>" >> "$BACK"
for ((i = 2; i <= $LINES; ++i)); do
FROM=$(sed -n "$(($i-1))p" "$FILES")
TO=$(sed -n "${i}p" "$FILES")
echo " <static>
<duration>$TIME.0</duration>
<file>$FROM</file>
</static>
<transition>
<duration>$ANIMATION.0</duration>
<from>$FROM</from>
<to>$TO</to>
</transition>" >> "$BACK"
done
FROM=$(sed -n 1p $FILES)
echo " <static>
<duration>$TIME.0</duration>
<file>$TO</file>
</static>
<transition>
<duration>$ANIMATION.0</duration>
<from>$TO</from>
<to>$FROM</to>
</transition>" >> "$BACK"
echo "</background>" >> "$BACK"
echo "The xml file was created."
echo "Putting the $BACK file as background."
gsettings set org.gnome.desktop.background picture-uri file://$BACK
echo "Deleting the temp file and finishing the execution."
die 0 $FILES
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment