Last active
November 23, 2021 10:03
-
-
Save shanehh/311e125bf52b0fe8e3336860b402acf9 to your computer and use it in GitHub Desktop.
cronjob to take a screenshot for my main monitor.. record my digital life.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
def save_path(): | |
import datetime as dt | |
from pathlib import Path | |
# file-naming | |
# https://softwareengineering.stackexchange.com/questions/61683/standard-format-for-using-a-timestamp-as-part-of-a-filename | |
timestamp = dt.datetime.now().strftime("%Y-%m-%dT%H-%M-%S%z") | |
p = (Path("~/Downloads/GooglePhotosSyncer") / timestamp).with_suffix(".png") | |
return str(p.expanduser()) | |
def is_screen_active(): | |
# https://stackoverflow.com/questions/52750812/detecting-lock-screen-on-mac-through-python3 | |
import Quartz | |
d = Quartz.CGSessionCopyCurrentDictionary() | |
return not "CGSSessionScreenIsLocked" in d.keys() | |
if __name__ == "__main__": | |
# for cronjob, macos only | |
if is_screen_active(): | |
# https://stackoverflow.com/questions/4524723/take-screenshot-in-python-on-mac-os-x | |
os.system( | |
'screencapture -x -C "{}"'.format(save_path()), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment