2009-11-28
Recently, after completing a web-based project, it was necessary to take multiple screenshot of the various states of the project's interface for a "take the tour" feature. Under normal circumstances, I would use the import command from imagemagick to take a screenshot but for some reason, import wouldn't capture the text on some form elements in firefox.

Off I went to find a screen capture app that does what I need, and after a minute of searching my distribution's software repository, and I had found, installed, and tested scrot (screen shot).

The icing on the cake would be to have a simple way to created incremented screenshots, so that I could end up with a set of images named
screenshot.png, screenshot001.png, screenshot002.png, screenshot003.png, etc.

Enter the python...
#!/usr/bin/env python import os.path import subprocess '''start defining some variables''' file_name "screenshot" # the base file name file_extension "png" # the image type save_path os.path.expanduser("~/"#where are we saving the screen shots increment #we may need to increment the file names save_file "%s.%s" % (file_name,file_extension# the default screen shot name #does the save file exist? while os.path.isfilesave_file ):     #the file exists, add and increment to the file name     increment+=1     if(increment10):         increment_string "00%i" % (increment)     elif(increment<100):         increment_string "0%i" % (increment)     else:         increment_string "%i" % (increment)     save_file "%s%s.%s" % (file_name,increment_string,file_extension) path_to_save_file os.path.join(save_path,save_file)    #what command do we need to run? command "scrot -q 100 %s" % ( path_to_save_file ) #run the command subprocess.call(command,shell=True)

Good and good. The script is named "screenshot", is in my ~/bin folder, and is keybound in my window manager to the "Print" key.

What about screen shots of opened drop-down lists? good question.
Bound to the keyboard combo of "Alt+Print" is the command
sleep 2; screenshot
which will delay for 2 seconds, which is enough time to open the dropdown, and then run screenshot.

As an added feature, scrot will beep when it captures the screen, so it is easy to tell when the delay has ended.
Comments
Name:
not required
Email:
not required (will not be displayed)
Website:
not required (will link your name to your site)
Comment:
required
Please do not post HTML code or bbcode unless you want it to show up as code in your post. (or if you are a blog spammer, in which case, you probably aren't reading this anyway).
Prove you are human by solving a math problem! I'm sorry, but due to an increase of blog spam, I've had to implement a CAPTCHA.
Problem:
7 minus 6
Answer:
required
  • Tags:
  • Python
subscribe
 
2016
2015
2014
2013
2012
2011
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008