How can i change the default name for the screenshots made by gnome-screenshot?

Gnome-screenshot 3.1.2 uses filenames like this one

Screenshot at 2011-07-31 12:13:04.png

making it rather easy to see when it was taken.

The problem is that it uses the colon ( : ) character - making it impossible to access such an image from Windows.

Considering I take most of my screenshots so I can send them to Windows users this has caused some problems.

Is there any way to change the default name that is used by the screenshot tool to replace the ":" with "." or "," ?


It is not actually possible change it easily, maybe you can help with this bug report.

(for the curious, check the source code. Currently, relevant line is 134)

Update: The bug was fixed upstream on 2015-01-28, replacing colons with dashes, which helps. But they didn't take the space out unfortunately.


gnome-screenshot doesn't allow setting a global default for the screenshot filenames, but you can use the -f option to specify a filename on the commandline.

We can use that to write a small bash script that will take the place of the original gnome-screenshot binary and will execute the original with the correct filename parameter.

Note that you will have to have root privileges for the following operations, so prefix each command with sudo or open a root shell with sudo -i.

  1. Move the original gnome-screenshot binary out of the way:

    dpkg-divert --add --rename --divert /usr/bin/gnome-screenshot.real /usr/bin/gnome-screenshot
    
  2. Open /usr/bin/gnome-screenshot in an editor (you should see a new empty file):

    editor /usr/bin/gnome-screenshot
    
  3. Paste the following two lines into the editor:

    #!/bin/bash  
    gnome-screenshot.real -f "$HOME/Pictures/Screenshots/$(date +%F_%H-%M-%S).png" $@
    

    You can insert any path you like after the -f; just make sure to enclose it in quotation marks and to keep the $@ after it.
    In this example, the screenshots will be stored with filenames like /home/yourusername/Pictures/Screenshots/2011-07-31_12-13-04.png. See man date for details on the date +%… syntax.

  4. Save the file and close the editor (e.g. using Ctrl + X in Nano or :wq in Vim).

  5. Make the newly created script executable:

    chmod a+x /usr/bin/gnome-screenshot
    

There is a simple and dirty way to rename all the screenshot taken immediately after the creation, but you will need to install inotify-tools ( apt-get install inotify-tools ) and then you could run this command:

while true; do inotifywait -e CREATE ~/Pictures && rename 's/\:/\./g' Pictures/Screenshot*.png; done;

While this command will run, every time you save a new screenshot in Pictures/, the script will rename every file containing :, substituting : with .

(Maybe you want change the directory, I don't know which directory Gnome 3 uses) If you really like it, you can start this command in a script every time gnome starts.


Instead of installing additional software and writing this code in the screenshot tool, here's a workaround to rename the files afterwards.

All you need to do is to navigate to the directory and run the following command

rename 's/\:/\-/g' *.png

This will replace all colons with dashes in all file names ending in .png of the ones present in the current directory.


Shutter is another application for taking screenshots which allows you to customize the file name: you can install it from Ubuntu Software Center.