Apple Script


set nowTime to my getCurrentDateString()

tell application "Finder"
	make new folder at desktop with properties {name:nowTime}
end tell

delay 2

repeat with p from 1 to 5000
	set pstr to p
	set pstr to text -3 thru -1 of ("00" & pstr)
	tell application "Kindle"
		tell application "System Events"
			do shell script "screencapture ~/Desktop/" & nowTime & "/" & pstr & ".png"
			key code 123
			delay 1
		end tell
	end tell
end repeat

-- return string (ex. '20171001124239')
to getCurrentDateString()
	set current_date to current date
	set val_year to year of current_date
	set val_month to month of current_date as number
	set val_day to day of current_date
	set val_hours to hours of current_date
	set val_minutes to minutes of current_date
	set val_seconds to seconds of current_date
	set date_time_string to ""
	if val_month < 10 then
		set val_month to "0" & val_month as string
	end if
	if val_day < 10 then
		set val_day to "0" & val_day as string
	end if
	if val_hours < 10 then
		set val_hours to "0" & val_hours as string
	end if
	if val_minutes < 10 then
		set val_minutes to "0" & val_minutes as string
	end if
	if val_seconds < 10 then
		set val_seconds to "0" & val_seconds as string
	end if
	set date_time_string to val_year & val_month & val_day & val_hours & val_minutes & val_seconds as string
	return date_time_string
end getCurrentDateString