Execute Script at random time

Hello,

i want to execute an appescript one time a day, every day. It would be great if the script would be executed, when im currently using the mac, because i want to take a picture and it would be better if i’m on this :smiley:

Is there a way to do this?

Do you use a screensaver? When it is running, you aren’t there presumably, and when it’s not you probably are.

tell application "System Events"
	if not (exists process "ScreenSaverEngine") then
		display dialog "Hey you're awake" with icon 2 -- or whatever.
	end if
end tell

To randomize the time of the event is a bit trickier. I would probably try for something like this which presumes that you would save it as a stay-open application and start it every morning.


set RN to random number from 21600 to 82799 -- 6AM to 1 sec to 11PM
on idle
	set T to time of (current date) -- returns seconds since midnight
	tell application "System Events" to set SS to not (exists process "screensaverengine")
	set Diff to T - RN
	if Diff < 0 then set Diff to -Diff
	if SS and Diff < 601 then
		display dialog "Bingo" -- or whatever
	else
		set RN to RN + 3600 -- add an hour
	end if
	return 600
end idle