Page 1 of 1

Keyboard shortcut doesnt output random numbers

Posted: Sat Aug 04, 2018 1:50 am
by WillBoxOwO
Hello there.
Im trying to configure a keyboard shortcut on Raspbian using the default GUI environnement, Openbox.

Im using the following piece of code I wrote to take screenshots using the raspi2png library wich supports OpenGL capture.
I modified the following configuration file: /home/pi/.config/openbox/lxde-pi-rc.xml

My goal is simple; When I hit CTRL+Alt+P, I want it to take a screenshot named with a random number.

Here is the code:

Code: Select all

    </keybind>
    <keybind key="C-A-P">
      <action name="Execute">
        <command>raspi2png -p Desktop/Screenshots/snap${RANDOM}.png</command>
      </action>
    </keybind>
    
Dont get me wrong; it works. But the "${RANDOM}" doesnt output a random number; it simply outputs "${RANDOM}".

Buut I tested the command in lxterminal and it outputs the random number...

What am I doing wrong?
Cheers.

Re: Keyboard shortcut doesnt output random numbers

Posted: Sat Aug 04, 2018 5:07 am
by DougieLawson
Try changing it from

Code: Select all

        <command>raspi2png -p Desktop/Screenshots/snap${RANDOM}.png</command>
to

Code: Select all

        <command>raspi2png -p Desktop/Screenshots/snap$(shuf -i 0-32767 -n 1).png</command>
Note: I've not tested that.

Re: Keyboard shortcut doesnt output random numbers

Posted: Sat Aug 04, 2018 4:39 pm
by WillBoxOwO
DougieLawson wrote:
Sat Aug 04, 2018 5:07 am

Code: Select all

        <command>raspi2png -p Desktop/Screenshots/snap$(shuf -i 0-32767 -n 1).png</command>
Note: I've not tested that.
Thanks for the reply! Sadly, it doesnt work. It works only in the terminal. The keyboard shortcut doesnt even take the screenshot using this command!

I then modified the command as follow:

Code: Select all

raspi2png -p Desktop/Screenshots/snap.png
And it works flawlessly using the keyboard shortcut- but theres no random number at the end of the file...
Would there be a way to launch the terminal in the background and make it run the command?

Re: Keyboard shortcut doesnt output random numbers

Posted: Sat Aug 04, 2018 4:57 pm
by klricks
WillBoxOwO wrote:
Sat Aug 04, 2018 4:39 pm
.....
Would there be a way to launch the terminal in the background and make it run the command?
Try:

Code: Select all

lxterminal -e raspi2png -p Desktop/Screenshots/snap$(shuf -i 0-32767 -n 1).png

Re: Keyboard shortcut doesnt output random numbers

Posted: Sat Aug 04, 2018 4:58 pm
by Paeryn
The command isn't being run by a shell so ${RANDOM} is being used literally, on the command line bash will replace that with a random number but since bash isn't invovled here it doesn't happen.

If you want to use shell features you can run it via bash yourself, something along the lines of

Code: Select all

<command>bash -c 'raspi2png -p Desktop/Screenshots/snap${RANDOM}.png'</command>

Re: Keyboard shortcut doesnt output random numbers

Posted: Sat Aug 04, 2018 5:34 pm
by WillBoxOwO
klricks wrote:
Sat Aug 04, 2018 4:57 pm
Try:

Code: Select all

lxterminal -e raspi2png -p Desktop/Screenshots/snap$(shuf -i 0-32767 -n 1).png
Again, it only works using the terminal... No screenshots are taken!
Plus, even if it worked, the screenshots wouldnt have worked out since it pops an lxterminal window everytime. Thanks tho!

Paeryn wrote:
Sat Aug 04, 2018 4:58 pm
If you want to use shell features you can run it via bash yourself, something along the lines of

Code: Select all

<command>bash -c 'raspi2png -p Desktop/Screenshots/snap${RANDOM}.png'</command>
Yay! This one seems to works! Thanks alot my friend!