Setting Wallpaper using sxiv and hsetroot

I’m trying to get sxiv (image viewer) to set wallpaper, I’m using the Arch Wiki article on sxiv (I’m not allowed to include links) to get this to happen, and it works perfectly fine, but the wallpaper resets every time I re-login/reboot. What I’m trying to do is every time I change the wallpaper I want the line starting with exec_always "hsetroot to be replaced with exec_always "hsetroot -fill '~the name of the image~'" in my i3 config (~/.config/i3/config)

The script is in ~/.config/sxiv/exec/key-handler (key-handler is the name of the script)

And this is what the script currently looks like:


# Example for $XDG_CONFIG_HOME/sxiv/exec/key-handler
# Called by sxiv(1) after the external prefix key (C-x by default) is pressed.
# The next key combo is passed as its first argument. Passed via stdin are the
# images to act upon, one path per line: all marked images, if in thumbnail
# mode and at least one image has been marked, otherwise the current image.
# sxiv(1) blocks until this script terminates. It then checks which images
# have been modified and reloads them.

# The key combo argument has the following form: "[C-][M-][S-]KEY",
# where C/M/S indicate Ctrl/Meta(Alt)/Shift modifier states and KEY is the X
# keysym as listed in /usr/include/X11/keysymdef.h without the "XK_" prefix.

rotate() {
	tr '\n' '\0' | xargs -0 realpath | sort | uniq | while read file; do
		case "$(file -b -i "$file")" in
		image/jpeg*) jpegtran -rotate "$degree" -copy all -outfile "$file" "$file" ;;
		*)           mogrify  -rotate "$degree" "$file" ;;

while read file
	case "$1" in
	"C-x")      xclip -in -filter | tr '\n' ' ' | xclip -in -selection clipboard ;;
	"C-c")      while read file; do xclip -selection clipboard -target image/png "$file"; done ;;
	"C-e")      while read file; do urxvt -bg "#444" -fg "#eee" -sl 0 -title "$file" -e sh -c "exiv2 pr -q -pa '$file' | less" & done ;;
	"C-g")      tr '\n' '\0' | xargs -0 gimp & ;;
	"C-r")      while read file; do rawtherapee "$file" & done ;;
	"C-comma")  rotate 270 ;;
	"C-period") rotate  90 ;;
	"C-slash")  rotate 180 ;;
	"C-w") hsetroot -fill "$file" && sed -i "s/^exec_always\ \"hsetroot.*|exec_always\ \"hsetroot\ -fill\ \'|$file\'\"" ~/.config/i3/config ;;

I added while read file and do above case "$1" in and the line "C-w") hsetroot -fill "$file" && sed -i "s/^exec_always\ \"hsetroot.*|exec_always\ \"hsetroot\ -fill\ \'|$file\'\"" ~/.config/i3/config ;;

Now, the hsetroot -fill "$file" part works perfectly, but the && sed -i "s/^exec_always\ \"hsetroot.*|exec_always\ \"hsetroot\ -fill\ \'|$file\'\"" ~/.config/i3/config ;;, doesn’t work at all! because I have no idea how to use sed, so I searched multiple terms and try and figure out how to do this, but clearly, I did not understand it, so would love to get some help on this, it does not need to be a sed, it can awk or anythings else.

And btw, I do know other programs such as nitrogen and feh would make this much easier, but this problem is probably very simple to solve for people who knows how to use tools like sed,awk and son on, but of course I don’t know for sure, cause I don’t know how to use them.

I figured it out,

"w") hsetroot -fill "$file" && sed -i "s|^exec_always \"hsetroot.*|exec_always \"hsetroot -fill '$file'\"|"

:point_up: that worked for me.

Also, apologies for my bad writing style, it probably didn’t even make sense to most lol

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.