GithubHelp home page GithubHelp logo

smudge / nightlight Goto Github PK

View Code? Open in Web Editor NEW
195.0 5.0 8.0 107 KB

A CLI for configuring "Night Shift" on macOS ๐ŸŒ•๐ŸŒ–๐ŸŒ—๐ŸŒ˜๐ŸŒ‘

License: MIT License

Rust 100.00%

nightlight's Introduction

nightlight

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 nightlight CLI aims to enable such access via a few simple commands. (Or, alternatively, via library access for other Rust tools.)

Installing

via Homebrew

brew install smudge/smudge/nightlight

via Cargo

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

cargo install nightlight

Usage

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

Command-Line Interface

Manual On/Off:

Turn Night Shift on (until tomorrow/sunrise):

nightlight on

Turn Night Shift off:

nightlight off

View current on/off status:

nightlight status

Toggle on or off based on current status:

nightlight toggle

Controlling the Temperature:

View current temperature setting:

nightlight temp

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

nightlight temp 70

Scheduling:

View the current schedule:

nightlight schedule

Start schedule from sunset to sunrise:

nightlight schedule start

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

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

Stop the current schedule:

nightlight schedule off

Rust API

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

nightlight = "0.3.0"

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

extern crate nightlight;

use nightlight::{NightLight, Schedule};

fn main() {
    let night_light = NightLight::new();

    if night_light.status().is_on() {
        night_light.off().unwrap(),
    }

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

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

Todo:

  • Ability to see current status of Night Shift
  • Ability to enable/disable sunrise/sundown schedule
  • Ability to enable/disable custom schedules
  • Ensure that changing schedule doesn't affect on/off state.
  • Make time display as properly-formatted 12-hour time
  • Use system config for time parse/format (12 vs 24).
  • API improvements
  • Consider command outputs: concise, human-readable, machine-parsable.
  • Full lib documentation
  • Test coverage of schedule/time parsing.
  • Tests that use fake/stub ObjC library.
  • Support for "Automatically adjust brightness" feature.
  • Other release mechanisms (like brew)
  • Cross-platform support (e.g. Windows' "Night Light")

Contributing

  • Check the issue tracker and consider creating a new issue.
  • Fork the project and create a new branch for your contribution.
  • Write, commit, and push your contribution to your branch.
  • Make sure the project builds (cargo build) and functionality still works as expected.
  • Submit a pull request.

Thanks To:

  • The team at Apple for introducing this feature in macOS Sierra
  • GitHub user jenghis for the (now archived) nshift repo/CLI
  • The maintainers of the Rust objc crate
  • Carol Nichols and Steve Klabnik for the official book on Rust
  • ABH, AF, CB, JP, and MK for brainstorming crate names with me

License

nightlight is released under the MIT License.

nightlight's People

Contributors

smudge avatar vitorgalvao 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

nightlight's Issues

Support Kelvin as temperature input

In addition to a number from 0-100 (the macOS config format) we can use a more standardized expression of color temperature, like so:

nightlight temp 4000K

Lower and upper bounds should be these (parity with Linux/GSettings night light):

nightlight temp 3500K
nightlight temp 6000K

Brew Install Error

mymac ~ % brew install smudge/smudge/nightlight
Error: Git is unavailable

`brew install` builds instead of using binary

The binary under releases works on my M1, why is it not used for brew install?
I don't want all the rust deps on this machine.

$ brew info smudge/smudge/nightlight
==> smudge/smudge/nightlight: stable 0.3.0
A CLI for configuring 'Night Shift' on macOS ๐ŸŒ•๐ŸŒ–๐ŸŒ—๐ŸŒ˜๐ŸŒ‘
https://github.com/smudge/nightlight
Not installed
From: https://github.com/smudge/homebrew-smudge/blob/HEAD/Formula/nightlight.rb
==> Dependencies
Build: rust โœ˜

$ brew install smudge/smudge/nightlight
==> Tapping smudge/smudge
Cloning into '/opt/homebrew/Library/Taps/smudge/homebrew-smudge'...
remote: Enumerating objects: 24, done.
remote: Counting objects: 100% (24/24), done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 24 (delta 4), reused 22 (delta 2), pack-reused 0
Receiving objects: 100% (24/24), done.
Resolving deltas: 100% (4/4), done.
Tapped 3 formulae (14 files, 9.5KB).
==> Fetching dependencies for smudge/smudge/nightlight: z3, llvm and rust
==> Fetching z3
==> Downloading https://ghcr.io/v2/homebrew/core/z3/manifests/4.12.4
######################################################################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/z3/blobs/sha256:db95e813c6ff08c47f749d56fad0d38c41c1448ef3f4ffd6ac4ba91c3c4123
######################################################################################################################## 100.0%
==> Fetching llvm
==> Downloading https://ghcr.io/v2/homebrew/core/llvm/manifests/17.0.6_1
######################################################################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/llvm/blobs/sha256:8d739bdfa4152d278627ff4724f240f7a946172b5d95622368e1e3768ab7
#######                                                                                                                    6.0%
^C

$ # download from releases and unzup

$ ~/Downloads/nightlight status
off until 23:00

Toggle functionality?

Any chance we can add functionality such that nightlight toggle toggles Night Shift?

Add automated tests

Now that the objectivec/macos backend has been abstracted out, we should create a testing backend so that we can at least test the general functionality without binding to OS-specific libraries. OS-level integration testing will still need to be done manually.

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.