Skip to content

Instantly share code, notes, and snippets.

@kode54
Created February 16, 2024 22:02
Show Gist options
  • Save kode54/bedda2d53cf130a134c132fc8cdd26c3 to your computer and use it in GitHub Desktop.
Save kode54/bedda2d53cf130a134c132fc8cdd26c3 to your computer and use it in GitHub Desktop.
Bing wallpaper grabber for SwayBG or for Wayfire shell
#!/bin/sh
# systemd example: https://stackoverflow.com/a/50321912
# cron example:
# 0 * * * * ~/.config/sway/scripts/bing_wallpaper.sh
# exit on error
set -e
if [ -z "$WAYLAND_DISPLAY" ]; then
export WAYLAND_DISPLAY=wayland-0
fi
wlpath=${WALLPAPER_PATH:-"$HOME/Pictures/BingWallpaper/"}
lswlpath=${LOCK_SCREEN_WALLPAPER_PATH:-"$HOME/lockscreen_wallpaper.jpg"}
baseurl="https://www.bing.com/"
wljson=$(curl $baseurl"HPImageArchive.aspx?format=js&idx=0&n=1&mbl=1&mkt=en-US" -s)
wldate=$(echo "$wljson" | jq '.images[].startdate' --raw-output)
wlurlbase=$(echo "$wljson" | jq '.images[].urlbase' --raw-output)
wluri="$wlurlbase""_""UHD.jpg"
wlname=$(echo "$wlurlbase" | sed -e 's/^.*[\\\/]//' -e 's/th?id=OHR.//')
wlfile="$wlpath$wldate""-""$wlname""_UHD.jpg"
if [ ! -f "$wlfile" ]; then
curl -s "$baseurl$wluri" > $wlfile
fi
killall swaybg || true
#swaymsg "output $output bg $wlpath fill"
swaybg -i $wlfile 2>&1 > /dev/null &
convert $wlfile -filter Gaussian -blur 0x8 -level 10%,90%,0.5 $lswlpath
#!/bin/sh
# systemd example: https://stackoverflow.com/a/50321912
# cron example:
# 0 * * * * ~/.config/sway/scripts/bing_wallpaper.sh
# exit on error
set -e
wlpath=${WALLPAPER_PATH:-"$HOME/Pictures/BingWallpaper/"}
lswlpath=${LOCK_SCREEN_WALLPAPER_PATH:-"$HOME/lockscreen_wallpaper.jpg"}
baseurl="https://www.bing.com/"
wljson=$(curl $baseurl"HPImageArchive.aspx?format=js&idx=0&n=1&mbl=1&mkt=en-US" -s)
wldate=$(echo "$wljson" | jq '.images[].startdate' --raw-output)
wlurlbase=$(echo "$wljson" | jq '.images[].urlbase' --raw-output)
wluri="$wlurlbase""_""UHD.jpg"
wlname=$(echo "$wlurlbase" | sed -e 's/^.*[\\\/]//' -e 's/th?id=OHR.//')
wlfile="$wlpath$wldate""-""$wlname""_UHD.jpg"
if [ ! -f "$wlfile" ]; then
curl -s "$baseurl$wluri" > $wlfile
fi
#swaymsg "output $output bg $wlpath fill"
crudini --set "${HOME}/.config/wf-shell.ini" background image "$wlfile" > /dev/null &
convert $wlfile -filter Gaussian -blur 0x8 -level 10%,90%,0.5 $lswlpath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment