You are not logged in.

#1 2009-07-31 15:26:07

Paaskehare
Member
From: Denmark
Registered: 2008-11-09
Posts: 59
Website

Python: Save a screenshot in a defined directory

Hi, I made this yesterday because I was annoyed that my PrintScrn button didn't do anything.

All it does is that it generates a filename, and then runs scrot to save the screenshot in a directory.

The filename is generated to contain the following:

DD-MM-YYYY_HH-mm-ss-(random number)

Example: 31-07-2009_17-27-19-660

The random number is a number between 1 and 10000 just to ensure that screenshots are not overwriting because you spam the script :-)

And now for the actual script:

file: screenshot

#!/usr/bin/python
# coding=UTF-8
# Filename : screenshot.py

'''
    This program was made by Paaskehare <Ole Bergmann>
     - www.paaskehare.dk
     - www.w0lf.biz

    Feel free to redistribute/edit/delete/burn/treat this program as you please.

'''

from os import system
from datetime import datetime
from random import randint

today = datetime.now()

number = str(randint(1,10000))

filename = today.strftime('%Y-%m-%d_%H-%M-%S-')+number+'.png'
filename = 'scrot /home/paaskehare/pic/screenshots/'+filename
try:
    system(filename)
except:
    print 'could not save screenshot.'

Just save it anywhere on your computer and give it executable permissions.

Remember to change the "/home/paaskehare/pic/screenshots/" to a directory of your choice.

You can now make the program work within any desktop environment, remember python and scrot are required.

How I got my PrintScrn button binded
I personally use openbox (3.4), so this one was an easy one for me, I just edited the rc.xml file to contain the following:

file: rc.xml

...
    <!-- Keybinding for print screen -->
    <keybind key="Print">
      <action name="Execute">
        <command>/home/paaskehare/Documents/python/screenshot</command>
      </action>
    </keybind>
...

Just change the directory to where you put the script and restart X smile

Last edited by Paaskehare (2009-08-05 12:17:37)


im.ole

Offline

#2 2009-08-01 00:28:51

HashBox
Member
Registered: 2009-01-22
Posts: 271

Re: Python: Save a screenshot in a defined directory

Since this is very related, here is my version, using xbindkeys

"scrot /home/hashbox/screenshots/`date +%d%m%y`.png"
 Sys_Req

Offline

#3 2009-08-01 03:46:52

coolaman
Member
From: france
Registered: 2008-07-28
Posts: 34
Website

Re: Python: Save a screenshot in a defined directory

Offline

Board footer

Powered by FluxBB