Skip to content

Instantly share code, notes, and snippets.

@lpenaud
Last active February 4, 2025 10:02
Show Gist options
  • Select an option

  • Save lpenaud/e5e422fac98d797ff4d98dcb335617c8 to your computer and use it in GitHub Desktop.

Select an option

Save lpenaud/e5e422fac98d797ff4d98dcb335617c8 to your computer and use it in GitHub Desktop.
Gnome slideshow

Gnome slideshow

Generate a slideshow to GNOME desktop background.

Usage

slideshow.sh INDIR > "slideshow.$(date -I).xml"

Example script

#!/bin/bash
# my-slideshow.sh

slideshow::init
# Add first image
slideshow::static "10" "IMG1.jpg"
# First image transition to the second one
slideshow::transition "5" "IMG1.jpg" "IMG2.jpg"
# Second image
slideshow::static "10" "IMG2.jpg"
# Second image transition to the third one
slideshow::transition "5" "IMG2.jpg" "IMG3.jpg"
# Second image transition to the third one
slideshow::static "10" "IMG3.jpg"
# Loop last image transtion to the first one.
slideshow::transition "5" "IMG3.jpg" "IMG1.jpg"
slideshow::end

Launch

./my-slideshow.sh > my-slideshow.xml

Thanks you

#!/bin/bash
function slideshow::init () {
cat <<EOF
<background>
<starttime></starttime>
EOF
}
function slideshow::end () {
cat <<EOF
</background>
EOF
}
# DURATION FILE
function slideshow::static () {
cat <<EOF
<static>
<duration>${1}</duration>
<file>${2}</file>
</static>
EOF
}
# DURATION FROM TO
function slideshow::transition () {
cat <<EOF
<transition type="overlay">
<duration>${1}</duration>
<from>${2}</from>
<to>${3}</to>
</transition>
EOF
}
# IMG [...IMG]
function slideshow::from () {
local first prev
slideshow::init
first="${1}"
slideshow::static 10 "${first}"
prev="${first}"
until [ $# -eq 0 ]; do
slideshow::transition 5 "${prev}" "${1}"
slideshow::static 10 "${1}"
prev="${1}"
shift
done
slideshow::transition 5 "${prev}" "${first}"
slideshow::end
}
function main () {
local indir="${1}" img
local -a imgs
local -i i
if [ $# -lt 1 ]; then
printf "Usage: %s INDIR\n" "${0}" >&2
return 1
fi
# Get all jpg files sorted by numerical order
mapfile -t imgs < <(find "$(realpath "${indir}")" -maxdepth 1 -type f -name "*.jpg" | sort -V)
if [ "${#imgs[@]}" -eq 0 ]; then
echo "No .jpg files found" >&2
return 1
fi
slideshow::from "${imgs[@]}"
}
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
main "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment