Last active
May 3, 2019 16:18
-
-
Save grvgr/0dfc4a8bb0f7fb78cb6d to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
# -*- mode: shell-script -*- | |
# requires: brew install brightness | |
execPath=/usr/local/bin/brightness | |
brightApps=(iTerm iTerm2 Emacs) | |
ignoreApps=(Alfred) | |
logFile=/tmp/auto.brightness.log | |
logEnable=false | |
# logEnable=true | |
high='1.000000' | |
low='0.500000' | |
# function current { echo $($execPath -l | tail -1 | awk '{print $NF}'); } | |
function log { $logEnable && echo $1: $currentApp >> $logFile; } | |
function bright { log 'bright'; $execPath $high; } | |
function dim { log 'dim'; $execPath $low; } | |
function ignore { log 'ignore'; } | |
while [ true ]; do | |
sleep 0.2 | |
previousApp=$currentApp | |
currentApp=$(lsappinfo info `lsappinfo front` | head -1 | awk '{print $1}' | grep -Eo '[^"]+') | |
if [[ $currentApp == $previousApp ]]; then | |
continue | |
elif [[ ${brightApps[*]} == *"$currentApp"* ]]; then | |
bright | |
elif [[ ${ignoreApps[*]} == *"$currentApp"* ]]; then | |
ignore | |
else | |
dim | |
fi | |
done |
This file contains 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
#> ~/Library/LaunchAgents/local.auto.brightness.daemon.plist | |
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>local.auto.brightness.daemon</string> | |
<key>KeepAlive</key> | |
<true/> | |
<key>RunAtLoad</key> | |
<true/> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/Users/gaurav/bin/auto.brightness</string> | |
</array> | |
<key>StartInterval</key> | |
<integer>5</integer> | |
<key>StandardOutPath</key> | |
<string>/tmp/auto.brightness.log</string> | |
</dict> | |
</plist> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment