I have a question on improving my current script…
basically with doing time calculations
what this does is grab the current sunset and sunrise times
and sets my 3 screens to various wallpaper sets throughout the day
also uses hue menu to set various presets of lights (that match my wallpapers)
when I take the sunset time - sunrise time and get a time diff between them and am using whole numbers rather than a time diff as i couldn’t figure out how to get a decent time calculation
IE sunset is 5:45 and a diff is 1:30, i want the sum of those to be 7.15 rather than 6.75
thanks
Darrin
set morningEarly to “Morning Early”
set morningLate to “Morning Late”
set afternoonEarly to “Afternoon Early”
set afternoonLate to “Afternoon Late”
set eveningEarly to “Evening Early”
set eveningLate to “Evening Late”
– get current days details from API
tell application “JSON Helper”
set AstroQuery to fetch JSON from “http://api.sunrise-sunset.org/json?lat=47.6768927&lng=-122.2059833&formatted=0”
set nowSunrise to my isoDateTimeString2Date(sunrise of results of AstroQuery)
set nowSunset to my isoDateTimeString2Date(sunset of results of AstroQuery)
end tell
set sunriseToday to (AST format date “HH.mm” of date nowSunrise) as number
set sunsetToday to (AST format date “HH.mm” of date nowSunset) as number
set diff to (sunsetToday - sunriseToday) div 4
– get current hour
set today to current date
set rightnow to (hours of today) & “.” & (minutes of today) as string as number
if (rightnow ≥ sunriseToday - 1 and rightnow < sunriseToday + diff) then
set periodOfDay to morningEarly
else if (rightnow ≥ sunriseToday + diff and rightnow < (sunriseToday + (diff * 2))) then
set periodOfDay to morningLate
else if (rightnow ≥ (sunriseToday + (diff * 2)) and rightnow < (sunsetToday - (diff * 2))) then
set periodOfDay to afternoonEarly
else if (rightnow ≥ (sunsetToday - (diff * 2)) and rightnow < sunsetToday - diff) then
set periodOfDay to afternoonLate
else if (rightnow ≥ sunsetToday - diff and rightnow < sunsetToday) then
set periodOfDay to eveningEarly
else if (rightnow ≥ sunsetToday or rightnow < sunriseToday - 1) then
set periodOfDay to eveningLate
end if
if (rightnow < 22.3 and rightnow > 5) then
tell application “/Applications/Hue Menu.app”
groups “Den”
preset periodOfDay
end tell
else
tell application “/Applications/Hue Menu.app”
all Off
end tell
end if
tell application “Finder”
try
set mainDisplayPicture to my getImageRight(periodOfDay)
set mainMonitorPicture to my getImageMain(periodOfDay)
set secondaryDisplayPicture to my getImageLeft(periodOfDay)
tell application "System Events"
set theDesktops to a reference to every desktop
set picture of item 3 of the theDesktops to secondaryDisplayPicture
set picture of item 2 of the theDesktops to mainMonitorPicture
end tell
set desktop picture to mainDisplayPicture
end try
end tell
on isoDateTimeString2Date(str)
return AST date with format “yyyy-MM-dd’T’HH:mm:ssZ” date string str
end isoDateTimeString2Date
on getImageRight(folderName)
tell application “Finder”
return some file of folder (“Pictures:Wallpapers:right:Time of Day:” & folderName) of home as text
end tell
end getImageRight
on getImageLeft(folderName)
tell application “Finder”
return some file of folder (“Pictures:Wallpapers:left:Time of Day:” & folderName) of home as text
end tell
end getImageLeft
on getImageMain(folderName)
tell application “Finder”
return some file of folder (“Pictures:Wallpapers:main:Time of Day:” & folderName) of home as text
end tell
end getImageMain
Model: macbook pro
Browser: Safari 602.3.12
Operating System: Mac OS X (10.13 Developer Beta 3)