34

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 "," ?

12

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.

  • 3
    +1 for linking to source code. Now THAT is the linux way. (Although the file name code is actually here, now: git.gnome.org/browse/gnome-utils/tree/gnome-screenshot/…) – Mark E. Haase Jul 16 '12 at 19:35
  • 1
    Unfortunately, the link is dead: No repositories found – gertvdijk Feb 4 '13 at 16:37
  • 2
    New URL: git.gnome.org/browse/gnome-screenshot/tree/src/… (retrieved at 2013-02-16 18:08 UTC+0800) – LiuYan 刘研 Feb 16 '13 at 10:08
  • I wish we could tweak this locally before good old GNOME developers wake up a little quicker to such important problems reported by users ;-) – Sadi Jan 18 '14 at 13:49
  • 3
    Whoever thought it a good idea to hardcode screenshot names in C, requiring a recompile of the entire desktop environment? Had no one ever thought that a user might want to change the default naming? Now that there is dconf-editor and such, and gnome-screenshot uses it, why not have a dconf entry stting for "screenshot naming policy" which you could set to say Screenshot-%02d.png, and if empty, then go along with the hardcoded naming policy? Eh.... – sdaau Mar 31 '16 at 8:41
10

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.

  • 3
    +1 This is a neat little trick, but your regex should be 's/\:/\./g' – Mark E. Haase Jul 16 '12 at 19:46
  • another option of replacement: use the unicode character – LiuYan 刘研 Feb 16 '13 at 10:35
  • Note that screenshots are saved by default in ~/Pictures, not ~/Desktop. – MestreLion Apr 4 '13 at 3:44
9

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.

6

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
    
4

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

  • 1
    Shutter is amazing by itself, and this is imho this is the best approach: instead of fixing bad filenames, do not produce them! – MestreLion Apr 4 '13 at 3:21
  • For example, the filename in the Shutter may have the following wildcard: $nb_name_%Y-%m-%d-%H%M%S. You can set it in the Preferences. – Vladimir S. Jun 13 '15 at 6:46
1

If:

  1. you are familiar with binary editing tools such as bless(see ubuntu package for example or github),
  2. and you know C string format modifiers,
  3. and you know the difference between 0x0 and "0",
  4. and you do not mind messing around with binary files installed by your Linux distribution of choice,

then you can modify the file name that is used by gnome-screenshot.

When binary editing gnome-screenshot, you will find two format strings:

  1. %Y-%m-%d %H-%M-%S followed by a null byte,
  2. and Screenshot from %s.%s followed by a null byte.

In the second format string, the first %s is the date, the second %s is the file extension.

From here, you can, for example, overwrite %Y-%m-%d %H-%M-%S with %F-%H%M%S followed by a null byte and Screenshot from %s.%s by shot %s.%s followed by a null byte: screenshots will then be named "shot 2018-05-05_174857.png" for example.

Adapt to your preferences.

There are two constraints:

  1. the new date format and the new file name format must not be longer than the original ones,
  2. your customizations will be destroyed if you install a new version of gnome-screenshot, for example when updating your system.

Warnings:

  • Tested on Ubuntu 16.04 LTS, your mileage may vary.
  • This is a hack, not a clean way of modifying the default name generated by gnome-screenshot: make a backup before proceeding.
  • Posted without any warranty of any kind.
0

In Debian 8.6 KDE → System settings → Custom shortcuts, I have set Trigger → PrtScn, and Action →

gnome-screenshot -p -f "$(date +%F_%H-%M-%S)_D.png"

and it works fine.

  • I wonder which Debian-version has been recent five years ago. – mook765 Oct 13 '16 at 16:03

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.