I'd like to take screenshots with a keyboard shortcut using scrot --select. I tried adding the following to my rc.lua to use the PrintScr key for this purpose:

awful.key({}, "Print", function () awful.spawn("scrot --select") end,
    {description = "take screenshot of selection", group = "client"}),

Unfortunately this results in the following error message in the xsession systemd journal:

giblib error: couldn't grab keyboard:Resource temporarily unavailable

It seems scrot needs to grab the keyboard while I'm still holding down the Fn+PrintScr combination. One way to work around this complicates the function a fair bit:

awful.spawn.with_shell("sleep 0.5 && scrot --select")

The .with_shell and sleep bits are a hack to give me time to release the keys before scrot runs. Which of course means that if I hold down the keys for too long the command still fails with the same error as above.

A more elegant workaround does not work reliably. I installed xdotool, set xdotool key XF86Ungrab && scrot --select as the screenshot command, and added grab:break_actions to services.xserver.xkbOptions, but I still get the same error as above most of the time. Pressing Fn+PrintScr repeatedly will eventually work, for no discernible reason.


Not a solution to your problem but it works if using maim instead of scrot. In addition I'm using xclip to automatically copy the image into my clipboard which is very handy.

awful.key({}, "#107",
  function ()
    awful.util.spawn_with_shell("FILE=" .. os.getenv("HOME") .. "/Media/Screenshots/snapshot-$(date +%Y-%m-%dT%H-%M-%S).png && maim -s --hidecursor $FILE && xclip -selection clipboard $FILE -t image/png")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.