You are not logged in.

#1 2020-07-15 18:54:41

Aldebaraan
Member
Registered: 2020-07-14
Posts: 12

[Solved] Open current wallpaper

I'm trying to make a right click menu option that opens up the current wallpaper that feh set up using

WPCURRENT="$(shuf -n1 -e ~/Pictures/Wallpapers/*)"
feh --randomize --bg-fill "${WPCURRENT}"

It's located in the ~/.fehbg.sh file:

#!/bin/sh
feh --no-fehbg --bg-fill '/home/username/Pictures/Wallpapers/harbour-3731x2721.jpg' 

how do i open it in a image viewer like xviewer?

I'm using obmenu generator btw:

    {item => ['command',              'Open wallpaper',                       'Open wallpaper']},

Last edited by Aldebaraan (2020-07-19 19:16:53)

Offline

#2 2020-07-15 19:18:25

damo
....moderator....
Registered: 2015-08-20
Posts: 6,124

Re: [Solved] Open current wallpaper

cat the script and pipe the text to eg awk, to extract the image filename

IMG=$(cat yourscript.sh | awk -F "'|/" '{print $9}')

Awk is using either "/" or "'" as the field delimiter. You may have to experiment with the field number, which I have guessed is 9!

Other options are to use sed, or bash parameter expansion, to extract the text. Or write the original image variable to another dotfile, and read that directly.

Put it in a script with the image viewer command, and run the script how you want.

#!/bin/sh

IMG=$(cat yourscript.sh | awk -F "'|/" '{print $9}')

bl-image-viewer "${IMG}" &
exit

Last edited by damo (2020-07-15 19:29:21)


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#3 2020-07-15 19:34:44

twoion
ほやほや
Registered: 2015-08-10
Posts: 2,902

Re: [Solved] Open current wallpaper

I think this would be a better way that will work as long as the command line in ~/.fehbg.sh is correctly escaped, and as long as feh comes first:

WALLPAPER_PATH=$(feh () { printf "%s\n" "${!#}"; exit 0; } && source ~/.fehbg.sh)

Not sourcing the file is more secure and better style though, however, since it is a script, the only way to get the result is to interpet it like a shell. That can be done for example using this Python script:

#!/usr/bin/env python3

import os
import shlex

with open(os.path.expanduser("~/.fehbg.sh"), "r") as FILE:
    for line in FILE:
        if line.startswith("feh"):
            print(shlex.split(line)[-1])
            break

raise SystemExit(0)

Per aspera ad astra.

Offline

#4 2020-07-15 20:26:52

Aldebaraan
Member
Registered: 2020-07-14
Posts: 12

Re: [Solved] Open current wallpaper

Uh i tried that and got a error in xviewer that no image was found.
Feh is adding a space to the end of the filename so maybe that's why:

#!/bin/sh
feh --no-fehbg --bg-fill '/home/username/Pictures/Wallpapers/8d326dfd84adfcec91f7b13e184134e8601 .jpg'

I tried:

#!/bin/sh
IMG=$(cat ~/.fehbg.sh | awk -F "'|/" '{print $9}')
xviewer "${IMG}" &
exit

Maybe extracting the variable and writing to a txt file should work? I don't know how to do that.

This is the script that changes the wallpaper. It is called inside .conkyrc:

#!/bin/bash
WPCURRENT="$(shuf -n1 -e ~/Pictures/Wallpapers/*)"

feh --recursive --randomize --bg-fill "${WPCURRENT}"

color=`convert "${WPCURRENT}" -gravity east -crop 20%x100% -resize 1x1 -negate txt:- | tail -n1 |cut -d' ' -f4`

echo -n '${color '$color'}' > ~/.config/openbox/wallchange/color.txt
echo -n ${WPCURRENT} > ~/.config/openbox/wallchange/currentwallpaper.txt

cat ~/.config/openbox/wallchange/color.txt

trying to write WPCURRENT to currentwallpaper writes only the folder path and not the filename with extension.

Last edited by Aldebaraan (2020-07-15 20:40:08)

Offline

#5 2020-07-16 11:14:50

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,069
Website

Re: [Solved] Open current wallpaper

@twoion,

What is that () magic?
Subshell?

feh ()

Last edited by brontosaurusrex (2020-07-16 11:15:39)

Online

#6 2020-07-16 11:20:45

twoion
ほやほや
Registered: 2015-08-10
Posts: 2,902

Re: [Solved] Open current wallpaper

brontosaurusrex wrote:

@twoion,

What is that () magic?
Subshell?

feh ()

Just a function declaration on 1 line smile It replaces the feh command in the PATH with the defined function of the same name (or alias) unless feh is then called using "command feh".


Per aspera ad astra.

Offline

#7 2020-07-16 11:22:52

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,069
Website

Re: [Solved] Open current wallpaper

Fancy. And shame on me to not recognize a function...

Last edited by brontosaurusrex (2020-07-16 11:31:56)

Online

#8 2020-07-17 08:15:26

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

Re: [Solved] Open current wallpaper

@all: you seem to be ignoring the fact that shuf will return a different image each time the script runs.

@Aldebaraan: use .fehbg -  the current bg image name is stored in ~/.fehbg and you can grep it from there thusly:

cut -d\' -f2 ~/.fehbg | tail -1

BTW, why don't you use feh as the image viewer...

Last edited by ohnonot (2020-07-17 08:17:49)


BL quote proposals to this thread please.
how to ask smart questions | my repos / my repos | my blog
---
Thank you for posting direct image links!

Offline

#9 2020-07-17 20:48:49

Aldebaraan
Member
Registered: 2020-07-14
Posts: 12

Re: [Solved] Open current wallpaper

Managed to make it work:
This picks a random wallpaper, saves the path and filename to currentwallpaper.txt:

#!/bin/bash
WPCURRENT="$(find ~/Pictures/Wallpapers/ -type f |shuf -n1)" 

feh --recursive --bg-fill "${WPCURRENT}"

color=`convert "${WPCURRENT}" -gravity east -crop 20%x100% -resize 1X1 -negate txt:- | tail -n1 |cut -d' ' -f4`

echo -n '${color '$color'}' > ~/.config/openbox/wallchange/color.txt
echo -n ${WPCURRENT} > ~/.config/openbox/wallchange/currentwallpaper.txt

cat ~/.config/openbox/wallchange/color.txt

This opens the image:

#!/bin/sh
IMG=$(cat ~/.config/openbox/wallchange/currentwallpaper.txt | awk -F "'|/" '{print $0}')
xviewer "${IMG}" &
exit

Obmenu schema:

    {item => ['bash ~/.config/openbox/wallchange/open-wallpaper.sh',              'Open wallpaper',                       'xviewer']},
    {item => ['bash ~/.config/openbox/wallchange/next-wallpaper.sh',              'Next wallpaper',                       'xviewer']},

Next i will try to make a history file for a 'Previous wallpaper' button. Thanks everyone!

Offline

#10 2020-07-18 12:16:07

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

Re: [Solved] Open current wallpaper

Aldebaraan wrote:

saves the path and filename to currentwallpaper.txt

Why, when this is exactly what ~/.fehbg does!
Also the "--recursive" is nonsensical in your feh command.

What does the convert part do?

BTW, the usage of `backticks` is discouraged, you should use $(command) instead.

Anyhow, glad you solved it.
Please edit your first post and prepend "[SOLVED]" to the title.


BL quote proposals to this thread please.
how to ask smart questions | my repos / my repos | my blog
---
Thank you for posting direct image links!

Offline

#11 2020-07-18 12:20:18

damo
....moderator....
Registered: 2015-08-20
Posts: 6,124

Re: [Solved] Open current wallpaper

And if you just want to open the image for viewing you can use feh for that as well.


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#12 2020-07-19 19:21:55

Aldebaraan
Member
Registered: 2020-07-14
Posts: 12

Re: [Solved] Open current wallpaper

ohnonot wrote:

What does the convert part do?

It's for conky:

conky.text = [[
${execpi 180 bash ~/.config/openbox/wallchange/wallchange.sh}
${execpi 5 cat ~/.config/openbox/wallchange/color.txt}

It changes the color used depending on the wallpaper.

ohnonot wrote:

Anyhow, glad you solved it.
Please edit your first post and prepend "[SOLVED]" to the title.

Done

damo wrote:

And if you just want to open the image for viewing you can use feh for that as well.

I don't use feh as image viewer because there's no zoom and neither a open image location button.

Offline

#13 2020-07-19 20:50:17

damo
....moderator....
Registered: 2015-08-20
Posts: 6,124

Re: [Solved] Open current wallpaper

Aldebaraan wrote:

...

damo wrote:

And if you just want to open the image for viewing you can use feh for that as well.

I don't use feh as image viewer because there's no zoom and neither a open image location button.

man feh

...

⟨keypad +⟩, ⟨Up⟩ [zoom_in]
             Zoom in

     ⟨keypad -⟩, ⟨Down⟩ [zoom_out]
             Zoom out

     *, ⟨keypad *⟩ [zoom_default]
             Zoom to 100%

     /, ⟨keypad /⟩ [zoom_fit]
             Zoom to fit the window size

     ! [zoom_fill]
             Zoom to fill the window size like --bg-fill

Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#14 2020-07-19 20:54:37

Nili
Member
From: $HOME/♫♪
Registered: 2015-09-30
Posts: 959
Website

Re: [Solved] Open current wallpaper

Aldebaraan wrote:

I don't use feh as image viewer because there's no zoom and neither a open image location button.

There is a zoom features on feh,

zoom_in 4
zoom_out 5

Place those to a file called buttons on /home/your-username/.config/feh/buttons
Then use the middle button from your mouse up and down to zoom in / zoom out.

Regarding the 2nd request, i just use File Manager to generate the thumbs then i open with feh. But i know there are a few scripts that help you to achieve the required purpose of browsing the images.

See more here if it helps you.
https://forums.bunsenlabs.org/viewtopic.php?id=704

Offline

#15 2020-07-23 19:49:52

Aldebaraan
Member
Registered: 2020-07-14
Posts: 12

Re: [Solved] Open current wallpaper

damo wrote:
Aldebaraan wrote:

...

damo wrote:

And if you just want to open the image for viewing you can use feh for that as well.

I don't use feh as image viewer because there's no zoom and neither a open image location button.

man feh

...

⟨keypad +⟩, ⟨Up⟩ [zoom_in]
             Zoom in

     ⟨keypad -⟩, ⟨Down⟩ [zoom_out]
             Zoom out

     *, ⟨keypad *⟩ [zoom_default]
             Zoom to 100%

     /, ⟨keypad /⟩ [zoom_fit]
             Zoom to fit the window size

     ! [zoom_fill]
             Zoom to fill the window size like --bg-fill
Nili wrote:
Aldebaraan wrote:

I don't use feh as image viewer because there's no zoom and neither a open image location button.

There is a zoom features on feh,

zoom_in 4
zoom_out 5

Place those to a file called buttons on /home/your-username/.config/feh/buttons
Then use the middle button from your mouse up and down to zoom in / zoom out.

Regarding the 2nd request, i just use File Manager to generate the thumbs then i open with feh. But i know there are a few scripts that help you to achieve the required purpose of browsing the images.

See more here if it helps you.
https://forums.bunsenlabs.org/viewtopic.php?id=704

Thanks.

Offline

Board footer

Powered by FluxBB