Skip to content

Instantly share code, notes, and snippets.

@brandonjp
Forked from jonobr1/auto-capture.scpt
Last active December 26, 2023 22:50
Show Gist options
  • Save brandonjp/6ed0b146ff4698b4f4b4590ae7c073f1 to your computer and use it in GitHub Desktop.
Save brandonjp/6ed0b146ff4698b4f4b4590ae7c073f1 to your computer and use it in GitHub Desktop.
A small AppleScript to take a screenshot every X minutes and run for Y hours. Saves to an Image with datetime to your specified folder. Great for recording your workday.
set dir to "~/Dropbox/Dropbox2/ScreenshotTimer/"
do shell script ("mkdir -p " & dir)
set intervalMins to 15 -- Change as per your desired frequency (in minutes)
set durationHours to 8 -- Change as per your desired duration (in hours)
-- Convert minutes to seconds for screenshot interval
set intervalSecs to intervalMins * 60
-- Calculate total repetitions within duration
set totalReps to durationHours * 60 / intervalMins
repeat totalReps times
set {year:y, month:m, day:d, hours:h, minutes:min, seconds:s} to (current date)
set dayStr to text -1 thru -2 of ("00" & d)
set monStr to text -1 thru -2 of ("00" & (m * 1))
set dateTime to (y & "-" & monStr & "-" & dayStr & "_" & h & "-" & min & "-" & s) as string
tell application "System Events"
set openWinsCount to count (every window of every process)
if openWinsCount > 0 then
do shell script ("screencapture " & dir & dateTime & ".png")
end if
end tell
delay intervalSecs
end repeat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment