Skip to content

Instantly share code, notes, and snippets.

@akaleeroy
Last active March 12, 2019 09:50
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save akaleeroy/fee7f0664da06b95fc6f682ae740a2e2 to your computer and use it in GitHub Desktop.
Disable f.lux when specific display connected
; Listens for display connected and checks its name against TARGET_DISPLAYS
; then automates "disable for fullscreen apps" option
; CONFIGURE your projector/TV here. Use the names from Screen resolution control panel
global TARGET_DISPLAYS := "MP-CL1A,SONY TV XV" ; MatchList
; [Beginner question and script for dual monitors](https://autohotkey.com/boards/viewtopic.php?t=6035)
OnMessage(0x7E, "onDisplayChange")
onDisplayChange() {
Sleep 500
; If projectors or TVs attached disable f.lux for fullscreen apps
setFluxFullscreenDisable(areDisplaysAttached(TARGET_DISPLAYS))
; Disregards software disconnection. If the cable is attached it counts
}
getMonitors() {
wmi := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" A_ComputerName "\root\wmi")
; SWbemObjectSet with InstanceName properties
return wmi.ExecQuery("Select * from WMIMonitorID")
}
areDisplaysAttached(targetUserFriendlyNames) {
areAttached := 0
For monitor in getMonitors() {
fname :=
for char in monitor.UserFriendlyName
fname .= chr(char)
if fname in %targetUserFriendlyNames%
areAttached = 1
}
return areAttached
}
; f.lux automation by registry write and restart
; :+1: no UI automation
; :-1: requires process restart for settings to take effect (FOHCTLAN)
; *[FOHCTLAN]: flash of high color temperature light at night
getFluxPath() {
A_DetectHiddenWindowsOld := A_DetectHiddenWindows
DetectHiddenWindows, On
WinGet, fluxPath, ProcessPath, ahk_exe flux.exe
DetectHiddenWindows, %A_DetectHiddenWindowsOld%
return fluxPath
}
restartFlux() {
fluxPath := getFluxPath()
Process, Close, flux.exe
; Try path from process and fallback to default if not
if (fluxPath)
; Set working dir to something that won't be moved or renamed
; because it will be locked while running
Run, %fluxPath%, "%LOCALAPPDATA%"
else
Run, "%LOCALAPPDATA%\FluxSoftware\Flux\flux.exe", "%LOCALAPPDATA%"
}
setFluxFullscreenDisable(val := "toggle") {
fluxPrefs = HKEY_CURRENT_USER\Software\Michael Herf\flux\Preferences
setting = fullscreendisable
; Read current setting value
RegRead, currentVal, %fluxPrefs%, %setting%
; No valid argument passed, toggle current value
val := !(val = 0 or val = 1) ? !currentVal : val
; Only if changed, save a restart cycle
if (val != currentVal) {
; Write new value
RegWrite, REG_DWORD, %fluxPrefs%, %setting%, %val%
restartFlux()
FileAppend, % setting "=" val "`n", *
}
return val
}
@akaleeroy
Copy link
Author

akaleeroy commented Mar 1, 2019

Alpha release, subject to change, made obsolete since f.lux 4.86 beta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment