Skip to content

Instantly share code, notes, and snippets.

@fergalmoran
Last active February 27, 2020 19:50
Show Gist options
  • Save fergalmoran/726089812397cb3ff9d95f304b33cd42 to your computer and use it in GitHub Desktop.
Save fergalmoran/726089812397cb3ff9d95f304b33cd42 to your computer and use it in GitHub Desktop.
Take a random screengrab from a movie file and set it as your background
#!/usr/bin/env bash
if [ ! -f "$1" ]; then
echo "No such file"
¦ exit 1
fi
suf="${1##*.}"
if [ "$suf" != "mp4" ] && [ "$suf" != "mkv" ] && [ "$suf" != "avi" ] && [ "$suf" != "mov" ] && [ "$suf" != "gif" ] && [ "$suf" != "flv" ]; then
echo "Input needs to be a video"
exit 1
fi
location="/home/fergalm/Pictures/Wallpapers/frame.png"
duration=$(ffmpeg -i "$1" 2>&1 | grep Duration | awk '{print $2}' | tr -d ,)
seconds=$(echo "$duration" | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')
seconds=${seconds%.*}
if [ "$seconds" -le 0 ]; then
echo "Error setting wallpaper"
exit 1
fi
randpoint=$((1 + RANDOM % "$seconds"))
ffmpeg -ss "$randpoint" -i "$1" -vframes 1 "$location" -y >>/dev/null 2>&1
gsettings set org.gnome.desktop.background picture-uri "file://$location"
xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitor0/image-path --set $location
xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitor1/image-path --set $location
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment