Skip to content

Instantly share code, notes, and snippets.

@bitsmanent
Last active September 2, 2024 14:24
Show Gist options
  • Save bitsmanent/204b24de2f0d36ac03f45783391a2786 to your computer and use it in GitHub Desktop.
Save bitsmanent/204b24de2f0d36ac03f45783391a2786 to your computer and use it in GitHub Desktop.
Rotate wallpapers of a given directory
#!/bin/sh
# Gist: https://gist.github.com/bitsmanent/204b24de2f0d36ac03f45783391a2786
DELAY=180
DEFAULT_PATH="$HOME/.wallpapers"
NEWLINE="
"
ARGV0="$(basename "$0")"
[ -n "$1" ] && path="$1" || path="."
die() {
echo $@
exit 1
}
getrpic() {
path="$1"
[ ! -d "$path" ] && exit 1
IFS="$NEWLINE"
shuf -n 1 -e "$path"/*
}
path="$1"
[ -z "$path" ] && path="$DEFAULT_PATH"
while true; do
pic="$(getrpic "$path")"
[ -z "$pic" ] && die "$ARGV0: $path: wrong or empty path"
tag="$(mimetype -b "$pic" 2>/dev/null |cut -d'/' -f1)"
[ "$tag" != "image" ] && die "$ARGV0: $pic: invalid image"
feh --bg-max --no-fehbg "$pic"
sleep "$DELAY"
done
@bitsmanent
Copy link
Author

Use this snippet to migrate from pexels.sh:

#!/bin/sh

# include resource file
. ~/.pexelsrc

for index in $(seq 1 48); do
	nitems=$NITEMS

	# get item url
	qs="per_page=1&page=$index"
	uri="https://api.pexels.com/v1/collections/$CID?$qs"
	json="$(curl -sH "Authorization: $APIKEY " "$uri")"
	pic="$(echo "$json" |sed -n 's/.*"original":"\([^"]*\).*/\1/p')"

	fn="$(basename "$pic")"
	echo curl -s --output "$HOME/.wallpapers/$fn" "$pic"
	curl -s --output "$HOME/.wallpapers/$fn" "$pic"
done

This should download all images from the collection.

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