Skip to content
This repository was archived by the owner on Sep 16, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ Night Shift Shell Utility
Simple shell utility to control the macOS Night Shift feature introduced in 10.12.4.

Usage is `nshift strength` where strength is a value from 0 to 100. A higher value shifts the color temperature of the display to more warm. A value of 0 disables Night Shift altogether.

Additional ways to use it are `nshift on`, `nshift off`, which do the obvious thing–turn NightShift on/off.

There is also `nshift reset`, _TL;DR: It turns NightShift on and off again._ This helps fixing some external displays which are somehow stuck on a warmer color tone after waking a Macbook from sleep, despite actually not working with NightShift in the first place. (Actually, the external display only reacts to NightShift being turned off, but never to being turned on. I don't know, don't ask.)
45 changes: 40 additions & 5 deletions nshift/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,45 @@
#import "CBBlueLightClient.h"

int main(int argc, const char * argv[]) {
if (argc == 1) { return 0; }
float strength = [[NSString stringWithUTF8String:argv[1]] floatValue] / 100;
CBBlueLightClient *client = [[CBBlueLightClient alloc] init];
if (strength != 0.0) { [client setStrength:strength commit:true]; }
[client setEnabled:(strength != 0.0)];
if (argc == 1) {
return 0;
}

CBBlueLightClient *client = [CBBlueLightClient new];

NSString *argument = [NSString stringWithUTF8String:argv[1]];

if ([@[@"--help", @"-h"] containsObject:argument]) {
NSArray *usageLines = @[@"Usage: nshift <0-100> to set strength",
@" nshift on to turn NightShift on",
@" nshift off to turn NightShift off",
@" nshift reset to cycle NightShift (turn it off and on) to help with some external displays",
@""];

printf([usageLines componentsJoinedByString:@"\n"].UTF8String);
}
if ([argument isEqualToString:@"off"]) {
[client setEnabled:NO];
}
else if ([argument isEqualToString:@"on"]) {
[client setEnabled:YES];
}
else if ([argument isEqualToString:@"reset"]) {
[client setEnabled:YES];
[client setEnabled:NO];
}
else {
float strength = [[NSString stringWithUTF8String:argv[1]] floatValue] / 100;

if (strength != 0.0) {
[client setStrength:strength commit:true];
[client setEnabled:YES];
}
else {
[client setEnabled:NO];
}
}

return 0;
}