Skip to content
This repository has been archived by the owner on May 27, 2023. It is now read-only.

Suggestion: Switch from Yahoo API to Night Shift's internal schedule #7

Closed
kirichkov opened this issue Sep 28, 2018 · 5 comments
Closed
Labels
enhancement New feature or request

Comments

@kirichkov
Copy link

As it appears MacOS will expose the night shift schedule as well as sunset/sunrise times on the command line using /usr/bin/corebrightnessdiag nightshift-internal.

Benefits of this approach is that dependence on external services can be completely abandoned (finding lat/long and sunset/sunrise times). Also this could be used to switch to dark/light mode using the native Night Shift schedule.

One issue to keep in mind is that times returned by corebrightnessdiag are in GMT and not in local time. The local timezone can be extracted from /etc/localtime.

@katernet katernet added the enhancement New feature or request label Sep 28, 2018
@katernet
Copy link
Owner

Amazing info @kirichkov thanks! I previously looked into using the night shift schedule and I could only find info on using the swift API, which would not benefit my bash script.

Taking a look it seems like I'll just be able to use corebrightnessdiag nightshift-internal with some awk and then convert to local time and store in the database. I'll look further into it.

@katernet
Copy link
Owner

Done

# Get Night Shift solar times (UTC)
riseT=$(/usr/bin/corebrightnessdiag nightshift-internal | grep nextSunrise | cut -d \" -f2)
setT=$(/usr/bin/corebrightnessdiag nightshift-internal | grep nextSunset | cut -d \" -f2)
# Convert to local time
riseTL=$(date -jf "%Y-%m-%d %H:%M:%S %z" "$riseT" +"%H:%M")
setTL=$(date -jf "%Y-%m-%d %H:%M:%S %z" "$setT" +"%H:%M")
# Store times in database
sqlite3 "$darkdir"/solar.db <<EOF
CREATE TABLE IF NOT EXISTS solar (id INTEGER PRIMARY KEY, time VARCHAR(5));
INSERT OR IGNORE INTO solar (id, time) VALUES (1, '$riseTL'), (2, '$setTL');
UPDATE solar SET time='$riseTL' WHERE id=1;
UPDATE solar SET time='$setTL' WHERE id=2;
EOF

@kirichkov
Copy link
Author

kirichkov commented Sep 28, 2018

👍 👍 👍 Thanks!

I'm closing it since you've implemented it in no time!

@kirichkov
Copy link
Author

UPDATE: It's working! Switched to dark mode in the evening, switched to light mode in the morning.

@katernet
Copy link
Owner

Sweet! Thanks for the idea @kirichkov

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants