nightshift

A CLI for configuring "Night Shift" on macOS 🌕🌖🌗🌘🌑

This crate also doubles as a Rust library. 🦀

Why?

The "Night Shift" feature on macOS is a convenient, built-in feature that can theoretically accomplish most of what third-party alternatives (like f.lux®) are capable of. However, as of now, there is no way to programmatically configure Night Shift (without entering the system preferences GUI), making its current usage more limited.

This nightshift CLI aims to enable such access via a few simple commands. (Or, alternatively, via library access for other Rust tools.)

Installing

Set up Rust/Cargo and install from crates.io by running:

cargo install nightshift

Or clone this repo and install from the local path:

cargo install --path .

Usage

First, make sure you are running macOS Sierra or newer.

Command-Line Interface

Turn Night Shift on (until tomorrow/sunrise):

nightshift on

Turn Night Shift off:

nightshift off

Set color temperature (a number from 0 to 100):

nightshift temp 70

Schedule from sunset to sunrise:

nightshift schedule

Set a custom schedule (in 12 or 24-hour time format):

nightshift schedule 19:45 6:00 nightshift schedule 7:45pm 6am

Disable the current schedule:

nightshift unschedule

View current schedule, on/off state, and color temperature preference:

nightshift status

Rust API

In addition to a CLI, nightshift can be pulled-in as a dependency for other Rust crates:

nightshift = "0.0.4"

Here's an example fn that toggles Night Shift off, changes the schedule and color temperature preference, and then toggles the feature back on:

```rust extern crate nightshift;

use nightshift::{NightShift, Schedule};

fn main() { let night_shift = NightShift::new();

if night_shift.status().unwrap().currently_active {
    println!("Turning Night Shift off...");
    night_shift.off().unwrap();
}

println!("Setting schedule and temperature...");
night_shift.set_schedule(Schedule::SunsetToSunrise).unwrap();
night_shift.set_temp(70).unwrap();

println!("Turning Night Shift on...");
night_shift.on().unwrap();

} ```

Todo:

Contributing

Thanks To:

License

nightshift is released under the MIT License.