Last active
April 13, 2016 14:12
-
-
Save krrr/2a01720d4a40adf23ccb to your computer and use it in GitHub Desktop.
Redshift GUI frontend for Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#SingleInstance | |
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. | |
#Warn ; Enable warnings to assist with detecting common errors. | |
SendMode Input ; Recommended for new scripts due to its superior speed and reliability. | |
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. | |
try { | |
Run, redshift.exe -V, , Hide | |
} catch { | |
MsgBox, redshift.exe missing! download one from https://github.com/jonls/redshift/releases | |
ExitApp | |
} | |
ReadConfig() | |
Menu, Tray, Add, &Auto, SetAuto | |
Menu, Tray, Add, &Day, SetDay | |
Menu, Tray, Add, &Night, SetNight | |
Menu, Tray, Add ; separator | |
Menu, Tray, Add, &Toggle Temporary Night, ToggleTemporaryNight | |
Menu, Tray, Add, &Edit Config, EditConfig | |
Menu, Tray, Add, &Exit, Exit | |
Menu, Tray, Click, 1 | |
Menu, Tray, Default, &Toggle temporary night | |
Menu, Tray, NoStandard | |
Gui, New ; without this script will exit | |
Set%initialMode%() | |
SetAuto() { | |
global location, dayTemp, nightTemp, extraOptions | |
Process, Close, redshift.exe | |
Run, redshift.exe -l %location% -t %dayTemp%:%nightTemp% %extraOptions%, , Hide | |
ChangeMode("Auto") | |
} | |
SetDay() { | |
global dayTemp | |
ChangeTemperature(dayTemp) | |
ChangeMode("Day") | |
} | |
SetNight() { | |
global nightTemp | |
ChangeTemperature(nightTemp) | |
ChangeMode("Night") | |
} | |
modeToRestore := currentMode | |
ToggleTemporaryNight() { | |
global currentMode, modeToRestore | |
if (currentMode = "Night") { | |
if (modeToRestore = "Night") | |
modeToRestore := "Auto" | |
Set%modeToRestore%() | |
} else { | |
modeToRestore := currentMode | |
SetNight() | |
} | |
} | |
Exit() { | |
Process, Close, redshift.exe | |
Run, redshift.exe -x, , Hide | |
ExitApp | |
} | |
ChangeTemperature(temp) { | |
global extraOptions | |
Process, Close, redshift.exe | |
Run, redshift.exe -r -l 1:1 -t %temp%:%temp% %extraOptions%, , Hide | |
} | |
ChangeMode(mode) { | |
global currentMode | |
currentMode := mode | |
for idx, m in ["Auto", "Day", "Night"] ; idx starts from 1 | |
if (m = mode) { | |
if (A_IsCompiled) | |
Menu, Tray, Icon, %A_ScriptFullPath%, %idx% | |
else | |
Menu, Tray, Icon, redshift-%m%.ico | |
Menu, Tray, Tip, Redshift mode: %mode% | |
Menu, Tray, Check, &%m% | |
} else | |
Menu, Tray, Uncheck, &%m% | |
} | |
ReadConfig() { | |
global | |
TryCreateDefaultConfigFile() | |
; IniRead, OutputVar, Filename, Section, Key [, Default] | |
IniRead, initialMode, redshift-tray.ini, Main, InitialMode, Auto | |
IniRead, dayTemp, redshift-tray.ini, Main, DayTemperature, 6500 | |
IniRead, nightTemp, redshift-tray.ini, Main, NightTemperature, 6000 | |
IniRead, location, redshift-tray.ini, Main, Location, "39.9:116.2" | |
IniRead, extraOptions, redshift-tray.ini, Main, RedshiftExtraOptions | |
} | |
TryCreateDefaultConfigFile() { | |
IfExist, redshift-tray.ini | |
return | |
text = | |
(Ltrim | |
# Redshift tray version 0.2 | |
[Main] | |
# choices: Auto, Day, Night | |
InitialMode=Auto | |
# the temperature of display should be 6500K when this application not running | |
DayTemperature=6500 | |
NightTemperature=6000 | |
# format: "latitude:longitude" | |
# how to get it: https://support.google.com/maps/answer/18539 | |
Location=39.9:116.2 | |
RedshiftExtraOptions= | |
) | |
FileAppend, %text%, redshift-tray.ini | |
} | |
EditConfig() { | |
global currentMode | |
RunWait, notepad.exe redshift-tray.ini | |
ReadConfig() | |
Set%currentMode%() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment