I'm trying to wrap my head around AppleScript. I have a simple project to capture screenshots every several seconds and save them to a folder.
I found this helpful script on GitHub:
I've altered it a bit in an attempt to change the file name to this format:
screen_shot 2019-04-05 at 5.23.13 PM.jpg
Yet, I end up with a filename like this:
screen_shot0Thursday
I could use some help sorting out how to properly use the date and time functions within the script.
Here is the script:
set dFolder to "~/Desktop/screencapture/"
set theDate to current date
do shell script ("mkdir -p " & dFolder)
set i to 0
repeat 960 times
do shell script ("screencapture " & dFolder & "screenshot_" & i & theDate & ".jpg")
delay 5 -- Wait for 5 seconds.
set i to i + 1
end repeat
Best Answer
If you really want to do everything in AppleScript, then you should try:
Note: With regards to AM/PM: I haven't tried this in the evening, but it should work
It would be way easier, however to use
do shell script
for this, e.g.:or even in one step by using:
Make sure to replace
username
with your actual username, and also that the folderscreencapture
exists. In summary, this results in:Note the importance of properly wrapping the filename in double quotes, which then needs to be escaped within AppleScript by a leading backslash: \"