Pragmatism in the real world

Sunrise and sunset times on the Mac command line

I recently discovered the /usr/libexec/corebrightnessdiag command line tool on macOS.

In particular, /usr/libexec/corebrightnessdiag nightshift-internal will give information about when the Mac’s nightshift settings, including when sunrise and sunset are!

$ /usr/libexec/corebrightnessdiag nightshift-internal
Night Shift Status
{
    AutoBlueReductionEnabled = 1;
    BlueLightReductionSchedule =     {
        DayStartHour = 7;
        DayStartMinute = 0;
        NightStartHour = 22;
        NightStartMinute = 0;
    };
    BlueReductionAvailable = 1;
    BlueReductionEnabled = 0;
    BlueReductionMode = 0;
    BlueReductionSunScheduleAllowed = 1;
    Version = 1;
} 
Night Shift Sunset/Sunrise
{
    isDaylight = 1;
    nextSunrise = "2024-12-17 08:20:24 +0000";
    nextSunset = "2024-12-17 15:49:34 +0000";
    previousSunrise = "2024-12-15 08:18:51 +0000";
    previousSunset = "2024-12-15 15:49:08 +0000";
    sunrise = "2024-12-16 08:19:39 +0000";
    sunset = "2024-12-16 15:49:19 +0000";
} 

Hence, we can easily output the today’s sunrise and sunset times with:

/usr/libexec/corebrightnessdiag nightshift-internal | grep -E "sunrise|sunset" | awk '{print $1, $4}'

This gives an output of:

sunrise 08:19:39
sunset 15:49:19

Useful!

I have, of course, created an Alfred workflow to get at the info easily!

Thoughts? Leave a reply

Your email address will not be published. Required fields are marked *