A bit of a noob at "sed", may need some help

On hyprland, I’m trying to point the image command in the swaylock config to my current wallpaper. I.E. image = [PATH TO CURRENT WALLPAPER].

Ok, so…I’m using azote to set my background in hyprland and it’s set to use the same location I use for Gnome backgrounds. Namely $HOME/.local/share/backgrounds.

I can use sed to get the information from azote as follows:

sed -n ‘/path/p’ $HOME/.local/share/azote/swabg.json

So far, so good. I run that command and I get this output.

“path”: “/home/jkmooney/.local/share/backgrounds/wallhaven-g8xlxd.jpg”,

The task I’m trying to figure out is how to first extract just that path from that string and then carry it over to my swaylock config for it to use to set as my image when the screen is locked.

Going through what docs I can find but, if anyone has any pointers, would be appreciated :slight_smile:

Finding values from json can be done with e.g. jq.
When you have the correct jq command, to get the path to a variable goes something like this:

the_path=$(jq ...)

where you fill the 3 dots with proper jq parameters.

1 Like

there’s a man page for jq…see what I can figure out.

Oh and, yes, I do realize that something like “grep backgrounds $HOME/.local/share/azote/swaybg.json” will get me the same output I got with sed but, I think I"m going to need sed (or maybe jq) to extract exactly what I need out of it.

Hold up…grep supports wildcards, and not just one character at a time if I use “.*”

So, grep -o /.local/share/backgrounds/.* $HOME/.local/share/azote/swaybg.json yields…


That’s a lot closer to what I need. should be easier to figure out how to fix it with sed from there.

I’d recommend jq because it is easier (once you study it), but with sed and its friends (awk, cut, grep, …) it is possible too.
Both ways something to learn. :wink:

Edit: this might work (but jq is generally more useful for json):

grep -oE "$HOME/\.local/share/backgrounds/[^\"]+"  $HOME/.local/share/azote/swaybg.json

(Hope I didn’t spoil your learning curve… :wink:)

I’d thought you needed something like egrep to do any actual manipulation. Thanks :slight_smile:

In any event, this was enough. Made the appropriate edits in my “lockscreen” file in /scripts and the config file in /swaylock and it’s working that want. Thanks for your help :slight_smile:

1 Like