As you know, I’m lazy.
Searching for my latitude, longitude values is too much work.
So I designed a script which does the entire job for me.
I’m just wondering if there is a way to force the URL to be open in Safari (which it does for me).
open location "http://www.sunset-times.com"
delay 1
tell application "System Events" to tell process "Safari"
set frontmost to true
tell window 1
--class of UI elements --> {splitter group, button, button, button, group, button, toolbar}
tell splitter group 1
--class of UI elements --> {splitter, tab}
tell UI element 2
--class of UI elements --> {group}
tell group 1
--class of UI elements --> {group}
tell group 1
--class of UI elements --> {scroll area}
tell scroll area 1
--class of UI elements --> {UI element, scroll bar}
tell UI element 1 # AXWebArea
--class of UI elements --> {group}
tell group 1
(*
class of UI elements --> {group, group, group, group}
tell group 1
its position --> {794, 160}
its size --> {1504, 248}
class of UI elements --> {group, image, group}
end tell
tell group 2
its position --> {961, 407}
its size --> {1170, 93}
class of UI elements --> {UI element}
end tell
*)
tell group 3
--its position --> {961, 531}
--its size --> {1170, 93}
--class of UI elements --> {group}
tell group 1
(*
class of UI elements --> {group, group, group, group, group, group, group, group, group}
tell group 1
class of UI elements --> {}
end tell
tell group 2
class of UI elements --> {}
end tell
*)
tell group 3
(*
class of UI elements --> {static text, static text, static text, static text, static text, static text, static text, static text, static text, static text, static text, static text, static text, static text, static text, static text, static text}
tell static text 1
its name --> "You seem to be located near "
end tell
tell static text 2
its name --> "Provence-Alpes-Cote d'Azur"
end tell
tell static text 3
its name --> " in "
end tell
tell static text 4
its name --> "France"
end tell
tell static text 5
its name --> ". Your local time is: 14:57:16 (13-Dec-2016)."
end tell
tell static text 6
its name --> "At this location, the sun will rise today at "
end tell
*)
tell static text 7
set sunriseTimeString to its name --> "07:57 "
end tell
(*
tell static text 8
its name --> "and sunset today will be at "
end tell
*)
tell static text 9
set sunsetTimeString to its name --> "16:55. "
end tell
end tell
end tell
end tell
(*
tell group 4
class of UI elements -->
end tell
*)
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end tell
set sunriseTimeString to my remplace(sunriseTimeString, {space}, "")
set sunsetTimeString to my remplace(sunsetTimeString, {".", space}, "")
set nowDateTime to current date
set seconds of nowDateTime to 0
set {hoursSunrise, minutesSunrise} to my decoupe(sunriseTimeString, ":")
copy nowDateTime to sunriseDateTime
tell sunriseDateTime
set its hours to hoursSunrise
set its minutes to minutesSunrise
end tell
set {hoursSunset, minutesSunset} to my decoupe(sunsetTimeString, ":")
copy nowDateTime to sunsetDateTime
tell sunsetDateTime
set its hours to hoursSunset
set its minutes to minutesSunset
end tell
copy nowDateTime to middayDateTime
tell middayDateTime
set its hours to 12
set its minutes to 0
end tell
set hoursAfterSunrise to (nowDateTime - sunriseDateTime) / hours
set hoursBeforeSunset to (sunsetDateTime - nowDateTime) / hours
set hoursAfterMidday to (nowDateTime - middayDateTime) / hours
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"
if (hoursBeforeSunset ≤ 0 or hoursAfterSunrise < -1) then
set periodOfDay to eveningLate
else if (hoursAfterSunrise < 1) then
set periodOfDay to morningEarly
else if (hoursAfterMidday < 0) then
set periodOfDay to morningLate
else if (hoursAfterMidday < 1) then
set periodOfDay to afternoonEarly
else if (hoursBeforeSunset > 2) then
set periodOfDay to afternoonLate
else
set periodOfDay to eveningEarly
end if
#=====
on decoupe(t, d)
local oTIDs, l
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set l to text items of t
set AppleScript's text item delimiters to oTIDs
return l
end decoupe
#=====
(*
replaces every occurences of d1 by d2 in the text t
*)
on remplace(t, d1, d2)
local oTIDs, l
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d1}
set l to text items of t
set AppleScript's text item delimiters to d2
set t to l as text
set AppleScript's text item delimiters to oTIDs
return t
end remplace
#=====
Yvan KOENIG running Sierra 10.12.1 in French (VALLAURIS, France) mardi 13 décembre 2016 16:00:52