Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

fluxbox call scrot -s

This is an obscure one, but it was useful for me and since I'm the only author on this blog, I get to choose what goes on here. If you don't like it, contact me and tell me that you have topics to share here. I already had fluxbox calling scrot for full-screen captures and window captures.

107      :Exec scrot   -z -e 'mv $f ~/Pictures'
Mod1 107 :Exec scrot -ubz -e 'mv $f ~/Pictures'

But I wanted to add an option to "select range" with scrot, i.e., to draw a rectangle around the area to capture. So the syntax for that is easy.

scrot -s -f -l 'style=dash,width=1' -z -e 'mv $f ~/Pictures'

But if you put that in an :Exec statement for fluxbox in ~/.fluxbox/keys, it fails. I placed it in a shell script and sent the output to an existing tty.

{
   scrot -s -f -l 'style=dash,width=1' -z -e 'mv $f ~/Pictures'
} 1>/dev/pts/3 2>&1

And running that with my hotkey in Fluxbox prints "couldn't grab keyboard" which was enough to search. Some guys in i3 inserted a delay, and then it works. So my final answer is pretty simple.

Ctrl 107 :Exec sleep 0.08 ; scrot -s -f -l 'style=dash,width=1' -z -e 'mv $f ~/Pictures'

Obviously my use of the floating decimal value to sleep depends on GNU sleep. I might be young, but I do remember when sleep only worked with integers. And about my 0.08, scrot did work with an even smaller delay in a shell script called by fluxbox, but when run by fluxbox itself, 0.05 didn't work and I needed the 0.08 delay. Haha, so that means there was the overhead of calling bash.

References

Weblinks

scrot/giblib: couldn't grab keyboard:Resource temporarily unavailable / Multimedia and Games / Arch Linux Forums

Comments