macOS: show for current location
Opened this issue · 0 comments
JayBrown commented
On macOS you can use the CoreLocationCLI to get your current location.
The script below will show the next 7 sunrises & sunsets for the current location, including conversion from UTC (GMT) to local time. Maybe it's of use to someone.
loc=$(CoreLocationCLI)
lat=$(echo "$loc" | awk '{print $1}')
long=$(echo "$loc" | awk '{print $2}')
[[ $lat == "-"* ]] && lat="$lat"S || lat="$lat"N
[[ $long == "-"* ]] && long="$long"W || long="$long"E
suntt=$(sunwait list 7 rise "$lat" "$long" | grep "^rises:")
count=0
while read sunt
do
pdate=$(date -v+"$count"d +"%a %d %b %Y")
up_utc=$(echo "$sunt" | awk '{print $2}')
down_utc=$(echo "$sunt" | awk '{print $5}')
up_local=$(date -jf "%H:%M %z" "$up_utc +0000" +"%H:%M")
down_local=$(date -jf "%H:%M %z" "$down_utc +0000" +"%H:%M")
echo -e "$pdate:\t☀︎ $up_local\t☾ $down_local"
((count++))
done < <(echo "$suntt")