0

Possible Duplicate:
Take a screenshot via a python script. [Linux]

How can I achieve the capturing screen-shots and saving in a folder as achieved by the following python code in windows in linux (ubuntu)? I also want to run it at the OS start-up.

import os
import sys
import time
import Image
import ImageGrab
SaveDirectory=r'C:\Documents and Settings\gg\Desktop\office_docs'

---------------------------------------------------------

for i in range(10000):

img=ImageGrab.grab()
saveas=os.path.join(SaveDirectory,'ScreenShot_'+time.strftime('%Y_%m_%d_%H_%M_%S')+'.png')
img.save(saveas)
time.sleep(10)
Community
  • 1
  • 1
Jack_of_All_Trades
  • 9,565
  • 13
  • 52
  • 80

1 Answers1

0

The first thing you should do, is replace the path of SaveDirectory with a path that works on both operating systems.

Based on How to get the home directory in Python?, you can use os.path.expanduser to replace ~ with your home directory.

A possible solution is:

from os.path import expanduser
import os.path.join

SaveDirectory = expanduser(os.path.join('Desktop', 'office_docs'))

For the second part of the question, it depends whether you want to do it via a GUI or manually editing a config file. Here you should find the instruction for the GUI. Here you can find the instructions for the config file way.

I should note that the python style guide suggest lowercase names with words separated by underscores for instance variables since it improves readability, but this is just a suggestion.

I hope you find this answer useful and apologise if it does not work as I have not tested it myself.

Community
  • 1
  • 1
Darian Lewin
  • 162
  • 1
  • 9
  • 1
    to get path for Desktop reliably on Windows see [Python, get windows special folders for currently logged-in user](http://stackoverflow.com/q/3858851/4279) – jfs Sep 27 '12 at 21:14