You are not logged in.

#1 2019-10-19 05:10:00

clusterF
Member
Registered: 2019-05-07
Posts: 257

fehsplash

Trying to learn how to shell script so here is something i thought to practice with.
Could be a lot better but with time i might be able to give it more options somehow in regards to feh and also maybe a gui front end using yad where you could choose the unsplash user gallery and or just set it to featured images plus set a resolution along with the feh desired background setting.

#!/usr/bin/env bash

# feh random wallpaper setting using https://source.unsplash.com/
# create $HOME/walls or just change $HOME/walls to your preferred wallpaper/desktop background directory
# dependancies = feh | wget
# put in your autostart file for a new desktop each login or create a .desktop file to change it on the fly
# im using images from unsplash user Jan Kronies https://unsplash.com/@jankronies
# only uses feh --bg-scale but im hoping to figure out how to incorporate other options like --bg-fill or --bg-tile 

if 	cd $HOME/walls; then
	wget -q https://source.unsplash.com/user/jankronies/1920x1080 -O jankronies
	feh --bg-scale jankronies;
	else echo "sumtingwong"
fi

Last edited by clusterF (2019-10-19 05:13:57)


"Thou Wanderer, Father of all! Thou Wanderer, Spirit of all!"

Offline

#2 2019-10-19 08:54:42

ohnonot
...again
Registered: 2015-09-29
Posts: 4,129
Website

Re: fehsplash

From a shell scripting point of view this is totally correct, except the 'else' does not logically belong to the 'if' block, the indentation should be sth like this (I also added "exit with return value error"):

#!/usr/bin/env bash

# feh random wallpaper setting using https://source.unsplash.com/
# create $HOME/walls or just change $HOME/walls to your preferred wallpaper/desktop background directory
# dependancies = feh | wget
# put in your autostart file for a new desktop each login or create a .desktop file to change it on the fly
# im using images from unsplash user Jan Kronies https://unsplash.com/@jankronies
# only uses feh --bg-scale but im hoping to figure out how to incorporate other options like --bg-fill or --bg-tile 

if 	cd $HOME/walls; then
	wget -q https://source.unsplash.com/user/jankronies/1920x1080 -O jankronies
	feh --bg-scale jankronies;
else
        echo "sumtingwong" && exit 1
fi

BUT...
feh can do all this by itself!

feh --bg-scale https://source.unsplash.com/user/jankronies/1920x1080

Offline

#3 2019-10-19 11:22:00

clusterF
Member
Registered: 2019-05-07
Posts: 257

Re: fehsplash

Oh so feh can download and display images from the web too, script is totally not needed then.

But where does feh keep the image? I would have thought /tmp but i cant find it on my system?


"Thou Wanderer, Father of all! Thou Wanderer, Spirit of all!"

Offline

#4 2019-10-19 12:10:33

clusterF
Member
Registered: 2019-05-07
Posts: 257

Re: fehsplash

Ok so a revision of this idea using select options bash menu.

Im wondering how i could set the wallpaper with the command in options and also save the wallpaper somewhere like $HOME/walls, what i cant figure out is where feh is downloading the wallpaper to using below commands?

#!/usr/bin/env bash

title="fehsplash wallpaper setter"
echo "$title"

PS3='Please enter your choice: '
options=("Center" "Fill" "Max" "Scale" "Tile" "Quit")
select opt in "${options[@]}"
do
    case $opt in
        "Center")
            feh --bg-center https://source.unsplash.com/user/jankronies/1920x1080
            ;;
        "Fill")
            feh --bg-fill https://source.unsplash.com/user/jankronies/1920x1080
            ;;
        "Max")
            feh --bg-max https://source.unsplash.com/user/jankronies/1920x1080
            ;;
        "Scale")
	    feh --bg-scale https://source.unsplash.com/user/jankronies/1920x1080
	    ;;
	"Tile")
	    feh --bg-tile https://source.unsplash.com/user/jankronies/1920x1080
            ;;
	"Quit")	
            break
            ;;
        *) echo "invalid option $REPLY";;
    esac
done

"Thou Wanderer, Father of all! Thou Wanderer, Spirit of all!"

Offline

#5 2019-10-19 15:46:06

clusterF
Member
Registered: 2019-05-07
Posts: 257

Re: fehsplash

another revision using getopts from this great tutorial here:
https://linuxconfig.org/how-to-use-geto … pt-options

also changed the url to select random images in 1920x1080 resolution.

so invoke command like so for a scaled image...

fehsplash -s
#!/bin/bash
set -e
set -u
set -o pipefail

while getopts 'cfmsta:' OPTION; do
  case "$OPTION" in
    c)
      feh --bg-center https://source.unsplash.com/random/1920x1080
      ;;

    f)
      feh --bg-fill https://source.unsplash.com/random/1920x1080
      ;;
    
    m)
	  feh --bg-max https://source.unsplash.com/random/1920x1080
	  ;;

	s)
	  feh --bg-scale https://source.unsplash.com/random/1920x1080
	  ;;
	  
	t) 
	  feh --bg-tile https://source.unsplash.com/random/1920x1080
	  ;;

    a)
      avalue="$OPTARG"
      echo "The value provided is $OPTARG"
      ;;
    ?)
      echo "script usage: $(basename $0) [-c] [-f] [-m] [-s] [-t] [-a somevalue]" >&2
      exit 1
      ;;
  esac
done
shift "$(($OPTIND -1))"

Last edited by clusterF (2019-10-21 11:56:02)


"Thou Wanderer, Father of all! Thou Wanderer, Spirit of all!"

Offline

#6 2019-10-21 21:00:59

ohnonot
...again
Registered: 2015-09-29
Posts: 4,129
Website

Re: fehsplash

clusterF wrote:

Oh so feh can download and display images from the web too, script is totally not needed then.

But where does feh keep the image? I would have thought /tmp but i cant find it on my system?

I'm pretty sure it downloads them to /tmp somewhere.
But, once the root window is set, there's no need to keep it anymore and it goes poof.
Personally, I think that makes it a very elegant solution, but if you want to keep the nice ones around for later, then it doesn't work that way.
But then you also shouldn't download them under the same filename, because that will always overwrite the previous one.

Offline

#7 2019-10-22 14:58:20

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,909
Website

Re: fehsplash

@clusterF, nice. Something similar by /me.

Example

wallnet -g satur -p

would permanently set said image (1st one starting with satur) from an internet list of urls/images.

Last edited by brontosaurusrex (2019-10-22 15:00:40)

Offline

#8 2019-10-23 11:39:04

clusterF
Member
Registered: 2019-05-07
Posts: 257

Re: fehsplash

Thanks brontosaurusrex, will give wallnet a try today, Cheers


"Thou Wanderer, Father of all! Thou Wanderer, Spirit of all!"

Offline

Board footer

Powered by FluxBB