I want to add command scrot -s as custom shortcuts via gnome-control-center keyboard. The accelerator key was Super+S.

enter image description here

but it didn't works.

If i remove -s or try other interactive command like xkill, they works fine.

Also, scrot -e 'mv $f ~/Pictures/scrot/' is works fine too.

So my question, why scrot -s didn't work and how can i fix it.

My distro is fedora 21, gnome version is 3.14.2, and scrot version 0.8

[UPDATE] gnome-screenshot -a is failed too.

[UPDATE 2] The default shortcut "Save a screenshot of an area to Pictures" is working fine, but i'm still curious why it didn't work when i set it to custom shortcuts. enter image description here

[UPDATE 3] The following is the error log results from custom shortcut command strace -v -s 1000000 -o /tmp/gnomescr.log gnome-screenshot -a:

$ grep -ni CRITICAL /tmp/gnomescr.log 
2660:write(2, "\n(gnome-screenshot:8700): Gdk-CRITICAL **: gdk_pixbuf_get_from_surface: assertion 'width > 0 && height > 0' failed\n", 115) = 115
2686:write(2, "\n(gnome-screenshot:8700): Gtk-CRITICAL **: gtk_window_resize: assertion 'width > 0' failed\n", 91) = 91
2748:write(2, "\n** (gnome-screenshot:8700): CRITICAL **: Unable to capture a screenshot of any window\n", 87) = 87
  • Create a script with these contents: scrot -s 2>~/scrot_error and run the script with your shortcut. Then, post the content of ~/scrot_error. – A.B. Mar 24 '15 at 9:07
  • 1
    There's empty file created if i run sh ~/test.sh from terminal, but no file created if i run it as a shortcut command, i.e. sh ~/test.sh. I tried strace for scrot and the error is "write(2, "giblib error: ", 14) = 14 and write(2, "couldn't grab keyboard:", 23) = 23" – 林果皞 Mar 24 '15 at 9:23
  • typo correction: the shortcut command is /bin/sh ~/test.sh – 林果皞 Mar 24 '15 at 14:09
  • "couldn't grab keyboard:"I have researched a bit, it seems to be a bug. The last release is 12 years old. – A.B. Mar 24 '15 at 14:18
  • The problem was gnome-screenshot -a failed too with different error. Or do you know how can i find the command bind to the default shortcut "Save a screenshot of an area to Pictures" ? /usr/share/glib-2.0/schemas/org.gnome.settings-daemon.plugins.media-keys.gschema.xml only give me something like <key type="s" name="area-screenshot"> <default>'&lt;Shift&gt;Print'</default> <summary>Take a screenshot of an area</summary> <description>Binding to take a screenshot of an area.</description> </key> but there's no information about the command it bind to. – 林果皞 Mar 24 '15 at 14:29

First, i tried strace parent processes like systemd and Xorg.bin, but i'm new to strace so i can't figure out.

Then i thought it might related to permission issue (su -, sudo, ...etc). So i plan to press the shortcut key as root. So i quickly realized i can use sudo xdotool key Super+s to test it. Then what's surprising me it just works!

So i try xdotool key Super+s without sudo and it still works. So i concluded that xdotool key Super+s is working fine, but still i can't figure out what's the difference between xdotool and key pressed from the strace log.

Then i come out an idea what if i put xdotool key Super+s as a custom shortcut ? So i created a new custom shortcut Super+J and bind to command xdotool key Super+s, in which Super+s already bind to command scrot -s. And it just works when i press Super+j

I tested gnome-screenshot -a and scrot -s and both works like a charm.

[UPDATE] I found this link, Issue 476: Xmonad should release key binding before spawning:

Reported by JohnTy...@gmail.com, Sep 18, 2011

Using scrot here to take screen shots. Scrot grabs the keyboard to listen for a keypress as a signal to abort. If the keyboard is not avaiable, it dies with error:

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

To test:

bind "scrot -s > /tmp/logfile" to a keypress in xmonad.hs

Activate keypress, nothing happens.

Check logfile, find error stated above.

I think it's a race condition because binding to "sleep 0.2; scrot -s" works here. The real problem is that xmonad is unnecessarily hanging on to keyboard and the spawned app is expecting it.

What version of the product are you using? On what operating system? 0.9.2/slackware linux

He use sleep to solve the similar problem. I tested it and it works. But I've to put it inside a shell script because custom command doesn't seems to support && or ; for concatenating multiple commands. But the time period of sleep 0.2 sometime doesn't work for me. The safe way is of course increase to sleep 0.5-1 second.

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.