I'm trying to get Gnome Screenshot to take and save screenshots with one keystroke, but I've run into a problem. The command I'm using works perfectly in the terminal, but not when i bind it to a key. When I press the bound key (Print Screen in this case), nothing happens. No error, nothing.

gnome-screenshot -f "$HOME/Pictures/Screenshots/Test $(date '+%F %T').png"

I'm currently trying different tweaks to the command. Currently, I've gotten it to work by omitting the path, but the "$(date "+%F %T")" part doesn't work properly when I do that, which puts me back where I was before. Before, it would take them with the same name and in my Home folder, causing them to be overwritten.

  • 1
    You'll have to use shutter or some other more advanced screenshot tool instead. See How can I install software or packages without Internet (offline)? on how to install it using your second computer. – muru May 15 '17 at 1:37
  • I've tried Shutter. It's about as slow as using Print Screen in Windows, as you have to manually save it each time. Gnome Screenshot normally pulls up a little dialog box asking if I want to to rename it or copy it to my clipboard, which I have to dismiss with Enter. Also, I got a different command to do exactly what I want, except it doesn't work when bound to a key. – Beth C May 15 '17 at 2:09
  • but it's far more flexible via command-line arguments (with date, time and counter based filenaming patterns available) – muru May 15 '17 at 2:11
  • I'm trying to quickly take screenshots while playing a game, and this one game is being a bit wonky with Steam's screenshot feature. I need one-keystroke screenshots, but I can't seem to get them set up! – Beth C May 15 '17 at 2:13
  • Update: Pressing they key is now causing the File, Edit, etc. menu to appear briefly on the Terminal. I feel almost like I should stop before I break something. – Beth C May 15 '17 at 2:19

Keybinding commands don't execute in a shell context. Therefore command interpolation doesn't work.

You can create a script in, say, $HOME/.local/bin/screenshot, that contains:

#!/usr/bin/env bash
gnome-screenshot -f "$HOME/Pictures/Screenshots/Test $(date '+%F %T').png"

chmod +x it, then bind the key you want to it.

You can also use scrot instead of gnome-screenshot, whose default filenames include a timestamp.

  • I've never used chmod. What does it do? I've also never made a script or bound it to a key. – Beth C May 16 '17 at 0:45
  • Oh, one more thing. When I looked it up, the instructions I found said to put #!/bin/bash at the beginning. I'm guessing it's different in this case? Those instructions were for making a basic script. – Beth C May 16 '17 at 21:45
  • #!/bin/bash says "execute the contents of this file using whatever's located at /bin/bash". #!/usr/bin/env bash says "find where bash is and execute this script with it". To make a script, create a text file, start it with one of those lines, and then execute on the command line: chmod +x $SCRIPTNAME. – dhasenan May 17 '17 at 0:55
  • Oh, so either one works? I guess I shouldn't have scribbled out /bin/bash in my notes then... Oh well. – Beth C May 17 '17 at 2:24

I've never used chmod. What does it do? I've also never made a script or bound it to a key.

chmod changes the permissions of a file. This setting determines who can read/write/execute a file. chmod +x allows the file to be executed directly. Further reading would be the manpage for chmod and this article exaplining shebangs.

Two other things worth nothing.

  1. Have you tried binding to a different key? Applications that have focus are generally able to decide how to handle input events. This means that steam could intercept the PrtSc, tell the OS that it handled the keypress, and then actually do nothing with it. This could be true for all keys leaving you out of luck.

  2. Full screen applications are generally rendered differently than windowed applications. Knowing that they are fullscreen allows the app to skip certain rendering steps which increases performance. I don't know enough to say for certain if this is actually the case, but its not unreasonable to think that the screenshot mechanism of the tool you are using isn't capable of capturing the screen of fullscreen apps. You could test this by running the game in windowed mode. Since it sounds like you can take screenshots of the game, albeit with a delay, this is probably not the issue.

  • For one, Steam does not do anything with PrtSc. It's only one game that the Steam Overlay's screenshot feature doesn't work with. A different variant of the command, gnome-screenshot --file=filename, did take the screenshot with one keystroke, but it would go to the Home folder and any other screenshots taken would overwrite the existing one. I tried putting the bit on the end that gives the other one a timestamp, but that didn't work. It ended up being pretty much the same command as before, but with the file path cut off. – Beth C May 16 '17 at 3:18
  • Oh, right, can't put line breaks in comments. The game is windowed, as the default utility alt-tabs me out of the game if I use that (it's about the best I've got right now) while the game's fullscreened or in borderless windowed mode. – Beth C May 16 '17 at 3:20
  • Actually, I have no idea where to start. For one, I have no idea how to make a script, two, just how do you chmod +x it? There's no way Google's gonna help with this because I feel like it's just so basic. – Beth C May 16 '17 at 3:22
  • If you take dhasenan's code and paste it into a text file, you've made a script (which, when I tested it myself, worked rather nicely). However, your computer doesn't know its a script, it only knows that its a file with some text in it. If you chmod +x the file, you're letting your computer know that the text file contains a script (something that can be run/executed rather than "just text"). You can do this graphically by right clicking on the file, going to properties, clicking the permissions tab, and checking the box that says "Allow executing file as a program." – Josh A. May 16 '17 at 3:40
  • Alternatively, you can open a terminal, navigate to the directory where your script is, and run chmod +x "your_script's_filename". Lastly, think of input events (key presses) as a game of telephone. Steam, being the current/focused application, is the first person to receive the phone call (key event). Steam can take that key even and do whatever it wants with it. Generally, if Steam received a key press and it didn't know what to do with it, it could lean over to its neighbor and pass it along (this is a huge oversimplification, so just go with me) or it could just not do anything. – Josh A. May 16 '17 at 3:44

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.