-- Set the Wallclocks to Sunrise and Sunset times
set theLatitude to 53.8008 --South is minus
set theLongditude to -1.5491 --West is minus
set theTimeOffset to 0 --Offset to GMT
set theDST to 1 --0 or 1 for daylight saving time
try
--get the sunrise and sunset times
set theURL to "https://api.sunrise-sunset.org/json?lat=" & (theLatitude as text) & "&lng=" & (theLongditude as text) & "&formatted=0"
set theAstronomical to do shell script "curl " & quoted form of theURL
--brute force parse JSON
set theSunriseHour to (text 4 thru 5 of (word 5 of theAstronomical)) + theTimeOffset + theDST
if theSunriseHour > 24 then set theSunriseHour to theSunriseHour - 24
set theSunriseMinute to word 6 of theAstronomical
set theSunSetHour to (text 4 thru 5 of (word 14 of theAstronomical)) + theTimeOffset + theDST
if theSunSetHour < 0 then set theSunSetHour to 24 + theSunSetHour
set theSunSetMinute to word 15 of theAstronomical
--set the wall clocks for next time
--cue SUNRISE is a cue with it's wall clock Trigger enabled and set to 24 Hours
--cue SUNSET is a cue with it's wall clock Trigger enabled and set to 24 hour
set theTime to (time of (current date))
tell application id "com.figure53.QLab.4" to tell front workspace
set wall clock hours of cue "SUNRISE" to theSunriseHour
set wall clock minutes of cue "SUNRISE" to theSunriseMinute
set wall clock hours of cue "SUNSET" to theSunSetHour
set wall clock minutes of cue "SUNSET" to theSunSetMinute
set theSunSetTime to (theSunSetHour * 3600) + (theSunSetMinute * 60)
set theSunriseTime to (theSunriseHour * 3600) + (theSunSetHour * 60)
--run the cue which would have run before the current time.
if theTime > theSunSetTime or theTime < theSunriseTime then
start cue "SUNSET"
else
start cue "SUNRISE"
end if
end tell
end try
Mic