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...
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
As an added feature, scrot will beep when it captures the screen, so it is easy to tell when the delay has ended.
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 = 0 #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.isfile( save_file ): #the file exists, add and increment to the file name increment+=1 if(increment< 10): 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
which will delay for 2 seconds, which is enough time to open the dropdown, and then run screenshot.sleep 2; 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