take screenshot with imagemagick in openbox via shortcut (rc.xml) on Linux

139 views Asked by At

I need to take screenshots and save them adding timestamp in filename.

The following command in terminal is working well:

import -window root -quality 100 screenshot_$(date +'%Y_%m_%d_%R_%S').jpg

I've inserted this in the .config/openbox/rc.xml

<keybind key="A-Print">
<action name="Execute">
<command>import -window root -quality 100 screenshot_"`date +%Y%m%d%R%S`".jpg
</command>
</action>
</keybind>

Then by Terminal:

openbox --restart

Now, If I click on PrtScn button Imagemagick takes a screenshot but saves it with +%Y_%m_0_%R_%S).jpg filename.

I've also tried to create a script file coping that command in a file script-screenshot-imagemagick.sh, I made it executable with chmod +x, I inserted this code in rc.xml:

<keybind key="A-Print">
<action name="Execute">
<command>/home/ste/Programmi-Installati/script-screenshot-imagemagick/script-screenshot-imagemagick.sh
</command>
</action>
</keybind>

but after restarting Openbox, if I click on PrtScn button Imagemagick takes a screenshot saving it with +%Y_%m_0_%R_%S).jpg filename again!

What is wrong? Perhaps the plus character is somehow disturbing...

thanks

1

There are 1 answers

0
svlasov On

Openbox does not do shell expansions. You need to pass your command directly to shell:

<command>bash -c 'import -window root -quality 100 screenshot_"`date +%Y%m%d%R%S`".jpg'</command>