Git Product home page Git Product logo

darkmode's Introduction

darkmode

download platform

Set macOS dark mode at sunset. If you have Alfred installed, the dark theme will also be set.

This shell script gets the sunrise and sunset times from Night Shift and automates the setting up of two user launch agents for sunrise and sunset, which then take over running the script thereafter. If your mac was asleep/off during the solar times, launchd will run the script when you're next logged in!

Or you can supply your own sunrise and sunset 24H times by passing arguments. Example: 0600 1800

News: macOS Catalina includes an 'auto' Dark Mode and the new version of Alfred remembers the theme set for light/dark mode and so basically there's no point in using this 😋. However, if you're on an earlier macOS release or you're a fan of setting your own Dark Mode schedules, then this is just for you!

Mojave and later

Mojave

High Sierra and below

HighSierra

Usage

$ ./darkmode.sh

OR

$ ./darkmode.sh HHMM HHMM

Notes

Compatible with macOS Mojave and later Dark Mode. Press OK to the security dialogs to allow control to System Events that appear when first running the script.

Night Shift requires Wifi and "Setting Timezone" enabled in System Preferences > Security & Privacy > Location Services > System Services > Details.

If your Mac does not support Night Shift, please use the previous version 1.7.2 which uses the Yahoo Weather API.

If you have a custom Alfred theme, you can change the name of the themes in the global variables.

A log file is stored in ~/Library/Logs which logs solar time changes and script errors.

To uninstall: $ ./darkmode.sh /u

darkmode's People

Contributors

cesarradtke avatar grgar avatar jsadoski avatar katernet avatar kzeni avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

darkmode's Issues

How do I remove this?

Can you please provide some details about how to remove this?
I have enjoyed this a lot, but I now want to get back to one theme.

New install, log shows ":StartCalendarInterval:Minute" Entry Already Exists

When uninstalling and reinstalling my logo shows:

05/10/18 14:03:35 darkmode: Solar query stored - Sunrise: 07:53 Sunset: 18:57
10/05/18 14:03:36 /Users/peter/Library/LaunchAgents/io.github.katernet.darkmode.sunset.plist: Could not find specified service
10/05/18 14:03:36 Add: ":StartCalendarInterval:Hour" Entry Already Exists
10/05/18 14:03:36 Add: ":StartCalendarInterval:Minute" Entry Already Exists

any idea?

How to uninstall?

The instructions are great, but is there a simple way to uninstall this plugin without breaking anything?

Sunrise/Sunset does not work

For some reason when I run the darkmode.sh script it correctly checks the current time and sets the mode accordingly, but does not automatically do so at sunrise and sunset.

> launchctl list | grep dark
-	78	io.github.katernet.darkmode.sunrise
-	78	io.github.katernet.darkmode.sunset

Mojave 10.14.4
Mid 2015 MacBook

cannot unsinstall

tried to uninstall many versions from terminal ./darkmode.sh /u (including the last update), once deleted the folder manually, yet mac sets itself to darkmode around sundown
MBA - macOS Mojave 10.14.1

Not switching back to light mode

I posted the issue here
#9 (comment)

but it was closed for some reason and I don't know how to re-open it (I have 3 jobs, so sometimes it can take a couple of days before I have the time to answer 😄).

Like it says in the original post... it is switching to dark mode just fine at night. It's just not switching back to light mode in the morning.

I have night shift on my ~4 years old macbook pro with Mojave.

Compatible with macOS Big Sur?

I used your script on macOS Catalina to have dark mode automatically changing based on my preferred time instead of Night Shift's time. After installing macOS Big Sur, I noticed that the script doesn't work sometimes. Like when i open my macbook at today morning, it doesn't automatically change to light mode.

I looked at the ~/Library/Logs/io.github.katernet.darkmode.log and i see these line:

12/17/21 09:32:52 darkmode: 105:109: execution error: Application isn’t running. (-600)

What do you think?

Not shifting on sunrise

When running darkmode.sh the first time (at night time) it shifted from light to dark (and installed all dependencies). But this morning it did not shift back to light.

When running darkmode.sh (from library/application support) it says
/Users/[MY_USERNAME]/Library/Application\ Support/darmode/darkmode.sh ; exit;
-bash: /Users/[MY_USERNAME]/.profile: No such file or directory
[MY_USERNAME]:~[MY_USERNAME]$ /Users/[MY_USERNAME]/Library/Application\ Support/darmode/darkmode.sh ; exit;

From the log file (io.github.katernet.darkmode.log)
10/01/18 22:41:03 Failed conversion of '' using format %Y-%m-%d %H:%M:%S %z''
10/01/18 22:41:03 date: illegal time format
10/01/18 22:41:03 usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
10/01/18 22:41:03 [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
10/01/18 22:41:03 Failed conversion of '' using format %Y-%m-%d %H:%M:%S %z''
10/01/18 22:41:03 date: illegal time format
10/01/18 22:41:03 usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
10/01/18 22:41:03 [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
01/10/18 22:41:03 darkmode: Solar query stored - Sunrise: Sunset:

"Error: Invalid arguments" when setting either parameter to 0800

Using parameters like ./darkmode.sh 0800 1930 produces this error:

Error: Invalid arguments. Usage: ./darkmode.sh HHMM HHMM
Exiting.

When testing each parameter evaluation individually (from line 281), this evaluation:

if (( $1 >= 0 && $1 <= 2400 )) && (( $2 >= 0 && $2 <= 2400 )); then

produces the error: ((: 0800: value too great for base (error token is "0800")

8 is being processed as an octal, not base 10.

Not authorized to send Apple events to System Events

On the latest beta

07/04/18 00:45:11 102:106: execution error: Not authorized to send Apple events to System Events. (-1743)
07/04/18 00:45:11 /Users/paranoidaditya/Documents/darkmode.sh: line 36: [[: File Doesn't Exist, Will Create: /Users/paranoidaditya/Library/LaunchAgents/io.github.katernet.darkmode.sunset.plist: syntax error: invalid arithmetic operator (error token is "'t Exist, Will Create: /Users/paranoidaditya/Library/LaunchAgents/io.github.katernet.darkmode.sunset.plist")
07/04/18 00:45:11 /Users/paranoidaditya/Documents/darkmode.sh: line 36: [[: File Doesn't Exist, Will Create: /Users/paranoidaditya/Library/LaunchAgents/io.github.katernet.darkmode.sunset.plist: syntax error: invalid arithmetic operator (error token is "'t Exist, Will Create: /Users/paranoidaditya/Library/LaunchAgents/io.github.katernet.darkmode.sunset.plist")
04/07/18 00:45:14 darkmode: Solar query stored - Sunrise: 05:26 Sunset: 21:40
07/04/18 00:45:14 102:107: execution error: Not authorized to send Apple events to System Events. (-1743)
07/04/18 00:46:17 102:107: execution error: Not authorized to send Apple events to System Events. (-1743)
07/04/18 00:46:20 102:107: execution error: Not authorized to send Apple events to System Events. (-1743)
07/04/18 00:46:25 102:107: execution error: Not authorized to send Apple events to System Events. (-1743)
07/04/18 00:46:32 102:107: execution error: Not authorized to send Apple events to System Events. (-1743)
07/04/18 00:46:38 102:107: execution error: Not authorized to send Apple events to System Events. (-1743)

Messages app doesn't fully change mode

Not sure what's going on here—this might be a macOS limitation—but sometimes (maybe 20% of the time, may be related to whether or not it's open) when I open my laptop in the morning my messages look like this.

Selected

Messages darkmode bug 1

Unselected

Messages darkmode bug 2

Mojave 10.14.4
Mid 2015 MacBook
darkmode 1.8.2

Illegal time format

Just posting this as a heads up: I saw this yesterday in the logs:

10/01/18 18:12:45 Failed conversion of ``'' using format ``%Y-%m-%d %H:%M:%S %z'' 10/01/18 18:12:45 date: illegal time format 10/01/18 18:12:45 usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 01/10/18 18:12:45 darkmode: Solar query stored - Sunrise: Sunset: 10/01/18 18:12:45 [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]

The script seems to still be running fine though.
Would it be related to the time format difference between US and where I am (Europe)?

Typo in beta branch

Line 122 of the beta branch currently says
sqlite3 /users/[redacted]/desktop/test.db <<EOF
but it should say
sqlite3 "$darkdir"/solar.db <<EOF
as in line 90 of the master branch

"Error: no such table: solar" with v1.5

The script is in ~/Library/Application Support/Darkmode. Running it with "./darkmode.sh" from that directory returns "07/01/18 11:00:21 Error: no such table: solar" in the logs.
After that, a zero kb solar.db file has been created and darkmode has been turned on (but it's 11AM).

Suggestion: Run on manual "night shift"

Hi, I have no clue if this is at all possible... currently this solution turns on dark mode based on the times setup in night shift right? What if we could toggle dark mode based on weather or not "night shift" was on? That would me to turn into complete low-light mode if I was working in a dark room... and allow me to just turn back to light mode if I was in bright conditions again.

Let me know if this is doable! 😃Happy to contribute, although I am no good writing bash scripts.

Daylight Savings Time Adjustments

Where I live (Eastern Standard Time, United States) I noticed that the darkmode script did not change when Daylight Savings Time kicked in a few weeks ago. My Nightshift won't kick in until much later in the evening (as expected), but the darkmode script still thinks it's dark outside much earlier in the day. Before DST went into affect, everything synced up nicely.

I wonder if this is related to #10 ?

Ability to provide specific light/dark schedule

katernet: Please submit any bugs with 1.9b in this issue.


That is, I'd like Light Mode to start at, for example, 06:00am and Dark Mode to start at, for example, 19:00pm.

If I could supply these values as arguments to the script and this will override the default behavior (change to Dark Mode on sunset) it'd be great!

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

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.