Command to automatically save screenshot after pressing hotkey

I’ve been pulling my teeth out trying to find out a way to automatically save a screenshot to a folder by pressing a hotkey, and append a counter or timestamp to the end of the filename. I found this which works well

import -window root ~/screenshot.png

but I need a way to add a counter so that it doesnt constantly override the same file when I press the hotkey, but will save a new screenshot in the same folder.

I’ve been looking at bash commands and scripts for the past 3 hours but havent found it yet, and it seems like it should be an easy task to perform.

Help would be appreciated. Thanks!

P.S. Also, If I wanted to change the command for the print screen key <Print> from “ksnapshot” to this command, how would I write it?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Simple enough:

import -window root ~/screenshot-date +%Y-%m-%d-%H:%M:%S.png

Good luck.

On 08/11/2010 10:36 PM, Supreme1012 wrote:
>
> I’ve been pulling my teeth out trying to find out a way to automatically
> save a screenshot to a folder by pressing a hotkey, and append a counter
> or timestamp to the end of the filename. I found this which works well
>
> import -window root ~/screenshot.png
>
> but I need a way to add a counter so that it doesnt constantly override
> the same file when I press the hotkey, but will save a new screenshot in
> the same folder.
>
> I’ve been looking at bash commands and scripts for the past 3 hours but
> havent found it yet, and it seems like it should be an easy task to
> perform.
>
> Help would be appreciated. Thanks!
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJMY4LWAAoJEF+XTK08PnB5DYwQAIwdLM86jDZkaxR9mU2LSmZN
45rDa79EcOqK58PErI6MOfheiIn/bi7054WBXyglPaw/Jdz/oIM61fjmWmY+q5kN
Fmtsbw9SmGVU1QHN8kgyFx34LIQNze8Lvmquo4FYv4CYVMXZlAzOMgxyzX9ezT0l
o/OsZ0xjxVlOfPHMTxYkidltVPjyh39REQLD/5K2Xwe8zd6Y2ejvpr5icHMV8pnm
T4fzqjgRvZm7mjGHhG0CIxO3CbgWHdn9SXsvjFpg7rMZcx9q5OJ7RAKnjajjK6Wh
OeQnNszAmp2eDZa7scvNSlCx9poBmbsL8NKbeDwduNA15uFWFYpjygaTOK0o0foG
B1A7pYlyfj1qBkFlfsVFQFGzH0SMXYYPnpuWy/0JUlWJSpyHYv3av5gxymCEB4XJ
NBY8rWN0IiizRUIpus+sqa57DModOfsmLSjnXkZg2MWljTx3SXcSFYNqU+rUo3LB
3rzqcUAv1YcFk3jY7ty0f2UdTH5AbHnvPSy6gGBQihWVCIS3RQvlISr9QBe5iWOx
H9DOV5DSluUvbpGLZV8AyWkd+1YRgqd94F3C9XcMlTUlP/BzPEV7Hlh9nbG5DA+q
BEUitCFWa2vXMDE5udpsLjqbwgVR+VbVYw3Xq9nxXn9PGuDOWc7qkvVsMN6xXtb0
/LMK3Bo1Y2lqeTEX1f1S
=pTpS
-----END PGP SIGNATURE-----

I’ve been tinkering and I found that date command, but everytime I include : in the name I end up with a 10.2 mb file. Replacing the “:” with something else seems to fix it

To change the shortcut, put that command into a script file:

#!/bin/bash
import -window root ~/screenshot-`date +%Y-%m-%d-%H:%M:%S`.png

and save it somewhere (~/bin/screenshot would be good)
and make it executable

chmod +x ~/bin/screenshot

then change the command in the kde shortcut whatnot from ksnapshot to /home/<user>/bin/screenshot (~/bin/screenshot should also work)

Hi
You could look at installing scrot? It automatically adds date, time
and image size eg;


2010-08-12-064920_3360x1050_scrot.png


Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 11.3 (x86_64) Kernel 2.6.34-12-default
up 8 days 21:06, 2 users, load average: 0.00, 0.03, 0.00
GPU GeForce 8600 GTS Silent - Driver Version: 256.44

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hmmm… quirks of the import command it would seem:

<quote source=“man import”>
By default, ‘file’ is written in the MIFF image format. To specify a
particular image format, precede the filename with an image format name
and a colon (i.e. ps:image) or specify the image type as the filename
suffix (i.e. image.ps). Specify ‘file’ as ‘-’ for standard input or output.
</quote>

Didn’t plan on that; good observation though.

Good luck.

On 08/12/2010 12:06 AM, Supreme1012 wrote:
>
> I’ve been tinkering and I found that date command, but everytime I
> include : in the name I end up with a 10.2 mb file. Replacing the “:”
> with something else seems to fix it
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJMY//EAAoJEF+XTK08PnB5Zl0P/2ySxPGa5t5Rq+qOquZ/VGeh
c4NahkWAs7gbwNCa1VNzzacUxJnsOWMa0MQRSVuG5wnZsmCCveUz/Om780PpmqqS
WxsUsGxaxgP0MHRYia3YPT7qikf4wjAU5Tc6fpRkRTwpBvYgH5jojshAuz53nOkt
TkqyrIrGX6VN/dqhllFVn55BJH4RBUz+/hcTFS6SMzWXOzY8PKVO0+7bbgHnovNX
bA9ASCSTl5R32SrSO9q5UmsAizuLF6NUlmWKcOdhsa+zXqVxVzPXpcsoKbs6olN5
8qzFqfYLP67tEPvQYo8w6IDhhI1OF2DmddsvAlauIU/ENP/VdbE5EKXrgZUsDWsE
tUlvhK+qqRmJFeR+Z/w3UlH0PuRw9GIyKGtZdYcjEsiDWlfYx9yVCnmG7T4ydY80
PtRgl/Q7v71VU5U9dPPY11SQmG61+h8lqFC5AwDBPzFYcfsl/JppTLlA0MxiND6M
t4xT0j8jwdYLegjRmTiA7zGNgKtGuysnZASKxBXChIhcGcZck+kezcnz/YzwOJmZ
rUhWO7BM0+3Uh8l5tG3Gdz2POSQMFHMMJ2mr7vc0whKjG5v+OqwJkIdzFgYTnU3v
CN6DgmAuoXWq/TsKvZvGGBRvCbHZFhqMa8MO2DslkaWUf/sgB/czByJ45gspNf1q
FWRl2C02xkxbsGVz1Eb3
=WDRr
-----END PGP SIGNATURE-----

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The original version I typed up used unixtime (seconds since the epoch, or
1970-01-01) instead of YYYY-MM-DD-HH:MM:SS but the way I made it is
more-intuitive for mere mortals. Using an alternate delimiter was a good
idea; if you don’t mind a big incrementing integer, one per second,
representing time you could just replace the date section with date +%s
and that will just give you seconds since 1970-01-01.

Good luck.

On 08/12/2010 08:05 AM, ab@novell.com wrote:
> Hmmm… quirks of the import command it would seem:
>
> <quote source=“man import”>
> By default, ‘file’ is written in the MIFF image format. To specify a
> particular image format, precede the filename with an image format name
> and a colon (i.e. ps:image) or specify the image type as the filename
> suffix (i.e. image.ps). Specify ‘file’ as ‘-’ for standard input or output.
> </quote>
>
> Didn’t plan on that; good observation though.
>
> Good luck.
>
>
>
>
>
> On 08/12/2010 12:06 AM, Supreme1012 wrote:
>
>> I’ve been tinkering and I found that date command, but everytime I
>> include : in the name I end up with a 10.2 mb file. Replacing the “:”
>> with something else seems to fix it
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJMZAAdAAoJEF+XTK08PnB5o4UQAJVY62Vd5glcBAeHX0Hghvk5
GfxjpJqFFK/C7xwlHxfIzp3pkwqarAFmqnMw/V3Ynjfz4Wzk7K2uDJvwHJD887TD
n4OL52PV6Oo4ELacL+IW1BsqambivV9uLUdWmwQhkZ7j123ELsY2+gvXbx6cj73P
sBpz9W5zHFaTgm+pT8lKMPIc/qvsfskzEkerSM3lBff6uN3FVRQprxU5pnsW03pP
qGLxOYJDyT092VbpWcdfp8D/ulo7MnxyUPVzvwEd+U4/Sb38lcj4pZqP81kT+o2S
tmc4zSb4Iu1Ts+w2jODkyN95A+hI30iR4u/mgJ8PqKI7UNkw9GQWYmoDy/z5HpZT
42+mE6AP32CEV8nZYmkBIc4dpZSoaHGQhfHoJC41tLXO6clOWnM8BaXlKf4QSWHr
TvYpOgizdP6//Q7Fv1/tGS559hYZjpL+kaQNxPrzrykuLiabII86vnzZsm7Rt0UT
/rSvyzNqj+6f7s0kNf29l0SUVAND5iEpxBSbPxIOOJtWw/s/EzIyR8A0VU9WSlpd
jzy2f/UbinP4KPfnWfzyHFbFc2WqiNldqi/xZDV/RODRWmdy6bILDbvj8QJiBySZ
/OsDSRsNOkTbVHKlJkQFfeG0gZl0yQv96RKaB3Ma2MMDtrmRT1VjmK5fAh8rxk0j
Nd/ktdWvKpRh03TegB0l
=jYuy
-----END PGP SIGNATURE-----

On 2010-08-12 06:36, Supreme1012 wrote:
>
> I’ve been pulling my teeth out trying to find out a way to automatically
> save a screenshot to a folder by pressing a hotkey, and append a counter
> or timestamp to the end of the filename.

Well, in Gnome the default capture screen button (prt-screen) does just that by default.

>:-)


Cheers / Saludos,

Carlos E. R.
(from 11.2 x86_64 “Emerald” GM (Elessar))