Is there a way tell python script to take a screenshot automatically and save it to desktop? All I am finding is great stuff on here, but it all seems to prompt to grab a selection after executing the script. I have found at least 5 pages on stackoverflow and none were automatic. Thanks
Asked
Active
Viewed 488 times
0
-
https://pypi.python.org/pypi/pyscreenshot Features: Capturing the whole desktop (then save it) in 3 lines: `import pyscreenshot as ImageGrab; im = ImageGrab.grab(); im.save('screenshot.png')` – chickity china chinese chicken Nov 09 '17 at 23:55
-
3Possible duplicate of [Take a screenshot via a python script. \[Linux\]](https://stackoverflow.com/questions/69645/take-a-screenshot-via-a-python-script-linux) – Patrick Haugh Nov 09 '17 at 23:55
-
no, that didn't help, already saw that page – P_n Nov 10 '17 at 00:17
-
`os.system("import -window root ~/Desktop/screenshot.png")`? ..(there's so many ways to do this it's almost subjective) – chickity china chinese chicken Nov 10 '17 at 00:19
1 Answers
0
This should do the trick on a mac (unix).
import os
os.system("screencapture screenshot.jpg")
You can read more here:
http://osxdaily.com/2011/08/11/take-screen-shots-terminal-mac-os-x/
And for linux this would do the trick:
import os
os.system("gnome-screenshot --file=screenshot.png")
For further gnome-screenshot commands type:
gnome-screenshot --help

alexisdevarennes
- 5,437
- 4
- 24
- 38
-
I know this works, but still waiting for me to grab the area and then It will screenshot it – P_n Nov 10 '17 at 00:02
-
Updated command, --window should be default. Hopefully it works now. – alexisdevarennes Nov 10 '17 at 00:08
-
1Still same issue, I am not sure what it is, but its always waiting for me to select the area for screenshot,. I will test it on different linux systems, thanks tho – P_n Nov 10 '17 at 00:15
-
What happens if you press prnt screen on your keyboard? Just an idea: Send the prnt screen key via python ? :) – alexisdevarennes Nov 10 '17 at 00:17
-
Don't have prnt on macbook :D but will test it on classic keyboard at home :) – P_n Nov 10 '17 at 00:19
-
-
Hopefully works now. Updated your title to reflect OS X also. – alexisdevarennes Nov 10 '17 at 00:30
-
Oh Its a Mac hardware but running linux on it :) But would like to possibly run my py scripts on mac as well – P_n Nov 10 '17 at 01:03