Adjust gamma so monitor doesn't mess up your body's clock

xrandr | sed -n 's/ connected.*//p' | xargs -n1 -tri xrandr --output {} --brightness 0.7 --gamma 2:3:4
[UPDATE: Now works for multiple connected outputs] I woke up around midnight with an urge to do some late night hacking, but I didn't want a bright monitor screwing up my body's circadian rhythm. I've heard that at night blue (short wavelength) lights are particularly bad for your diurnal clock. That may be a bunch of hooey, but it is true that redder (longer wavelength) colors are easier on my eyes at night. This command makes the screen dimmer and adjusts the gamma curves to improve contrast, particularly darkening blues and greens (Rɣ=2, Gɣ=3, Bɣ=4). To reset your screen to normal, you can run this command: xrandr | sed -n 's/ connected.*//p' | xargs -n1 -tri xrandr --output {} --brightness 1 --gamma 1:1:1 or, more briefly, xgamma -g 1 Note: The sed part is fragile and wrong. I'm doing it this way because of a misfeature in xrandr(1), which requires an output be specified but has no programmatic way of querying available outputs. Someone needs to patch up xrandr to be shell script friendly or at least add virtual outputs named "PRIMARY" and "ALL". . Todo: Screen should dim (gradually) at sunset and brighten at sunrise. I think this could be done with a self-resubmitting at job, but I'm running into the commandlinefu 127 character limit just getting the sunrise time: wget http://aa.usno.navy.mil/cgi-bin/aa_pap.pl --post-data=$(date "+xxy=%Y&xxm=%m&xxd=%d")"&st=WA&place=Seattle" -q -O- | sed -rn 's/\W*Sunrise\W*(.*)/\1/p' I hope some clever hacker comes up with a command line interface to Google's "OneBox", since the correct time shows up as the first hit when googling for "sunrise:cityname". . [Thank you to @flatcap for the sed improvement, which is much better than the head|tail|cut silliness I had before. And thank you to @braunmagrin for pointing out that the "connected" output may not be on the second line.]
Sample Output
There is no output, but here's the output from xrandr so you can see the input to the sed regex. It is simply grabbing the first word from any line that says "SUCHANDSO connected"
$ xrandr
Screen 0: minimum 320 x 200, current 1600 x 1200, maximum 4096 x 4096
VGA-0 connected 1600x1200+0+0 (normal left inverted right x axis y axis) 352mm x 264mm
   1920x1440      60.0 +
   1024x768       85.0 +   85.0     75.1     75.0     70.1     60.0  
   1856x1392      60.0     60.0  
   1792x1344      60.0     60.0  
   1920x1200      59.9  
   1600x1200      85.0*    75.0     75.0     70.0     65.0     60.0  
   1680x1050      84.9     74.9     69.9     60.0  
   1600x1024      60.2  
   1400x1050      85.0     85.0     74.9     74.8     70.0     60.0     60.0  
   1280x1024      85.0     75.0     60.0  
   1440x900       84.8     75.0     59.9  
   1280x960       85.0     60.0  
   1360x768       60.0     59.8  
   1280x800       84.9     74.9     59.8  
   1152x864      100.0     85.1     85.0     75.0     75.0     70.0     60.0  
   1280x768       84.8     74.9     59.9  
   832x624        74.6  
   800x600        85.1     85.1     72.2     75.0     60.3     56.2  
   848x480        60.0  
   640x480        85.0     75.0     72.8     75.0     60.0     59.9     59.9  
   720x400        85.0     70.1  
   640x400        85.1  
   640x350        85.1  
S-video disconnected (normal left inverted right x axis y axis)

What Others Think

Hey this is a really cool idea. I have thought about something similar, but never really knew how to do it. You said you were running out of room on CLF's 127 character business. If you figure out how to do the dimming will you send it to me? Thanks!
thingsgoboom · 630 weeks and 5 days ago
Let me try that again. Redshift, works great for this. http://www.omgubuntu.co.uk/2010/05/alleviate-tired-eyes-in-ubuntu-with-redshift/
binarysys · 630 weeks and 5 days ago
All that nonsense: head -2 | tail -1 | cut -f1 -d' ' can be simplified to: sed -n '2{s/ .*//;p}' Meaning: sed -n # don't output anything 2{...;...} # when you get to line 2 perform some commands s/ .*// # search for a space and other stuff, replace with nothing p # print the result
flatcap · 630 weeks and 4 days ago
Maybe you could use: `xrandr | grep "[^s]connected"` instead. This searches in the output of xrandr for the output that is connected, which may not be in the second line.
braunmagrin · 630 weeks and 2 days ago
I`m sorry. xrandr on Ubuntu 10.04 doesn't have the brightness option. Try to use this instead, it works even if the connected output isn't in the second line. xrandr --output `xrandr | grep "[^s]connected" | cut -f1 -d' '` --gamma 2:3:4 "grep [^s]connected" searches for a expression that contains "connected" with any character before, besides 's' (from "disconnected").
braunmagrin · 630 weeks and 2 days ago
@braunmagrin: Fair enough. Try this: sed -n '/ connected/{s/ .*//;p}' Fewer characters and only one process started rather than two.
flatcap · 629 weeks and 6 days ago
@flatcap, @braunmagrin thanks for the tips! @thingsgoboom here are a pair of self-resubmitting scripts which set the gamma appropriately and then use "at" to schedule the other script to run. Put the contents of these into files in your path (e.g., your home directory), mark them executable, and then run one of them. As long as you stay logged on, they will keep running each other at the correct time. . ~/bin/nighttime.sh xrandr \ | sed -n 's/ connected.*//p' \ | xargs -n1 -tri xrandr --output {} --brightness 0.7 --gamma 2:3:4 \ || exit 1 echo `env` daytime.sh | at $(wget http://aa.usno.navy.mil/cgi-bin/aa_pap.pl --post-data=$(date "+xxy=%Y&xxm=%m&xxd=%d")"&st=WA&place=Seattle" -q -O- | sed -rn 's/.*Sunrise\W*(.*)/\1/p' | tr -d . ) >/dev/null 2>&1 . ~/bin/daytime.sh xgamma -q -g 1 || exit 1 echo `env` nighttime.sh | at $(wget http://aa.usno.navy.mil/cgi-bin/aa_pap.pl --post-data=$(date "+xxy=%Y&xxm=%m&xxd=%d")"&st=WA&place=Seattle" -q -O- | sed -rn 's/.*Sunset\W*(.*)/\1/p' | tr -d . ) >/dev/null 2>&1 . You'll have to remove the $ from the front of each line, of course. I only put it there because that's the only way commandlinefu lets me markup that something is code.
hackerb9 · 629 weeks and 3 days ago
Pug Puppies for Sale Near Me pugs puppies for sale teacup pugs for sale pug puppies for sale by owner pug puppies ohio PUG PUPPY FOR SALE NEAR ME PUG PUPPIES FOR SALE pug puppies for sale in kentucky Pug Puppies for Sale Under $500 Near Me pug puppies for sale in texas pug puppies for sale $200 pugs for sale near me under $500 pugs for sale under $400 near me pugs for sale near me puppies for sale near me under $500 pug puppies for sale under $1,000 near me pug for sale pug puppies for sale under $300 Brindle Pug Pitbull Pug Mix Pugs for sale cheap Cheap pug affordable pug puppies for sale near me black pugs for sale near me White Pugs for sale pug dog for sale free pug puppies pug puppies for sale in my area mn pug breeders pug puppies indiana pugs for sale michigan PUG PUPPY ADOPTION Pug puppies for sale Pug puppies for sale near me Pug puppies near me Pug Puppies for Sale Under $500 Near Me Cute Pug Puppies Black pug puppies Black pug puppies for sale pug puppies for adoption black pug puppies for sale near me chihuahua pug mix puppies how much is a pug puppy teacup pug puppies baby pug puppies pictures of pug puppies pug puppies for sale in Ohio pug puppies price pug mix puppies teacup pug puppies for sale best food for pug puppy newborn pug puppies pug puppies craigslist pug puppies for sale craigslist adorable pug puppies how much does a pug puppy cost Pitbull pug mix puppies pug pit mix puppy pug puppies for sale $200 pug puppies for sale in NJ Pug puppies for sale in Wisconsin pug puppy cost pug puppy food royal canin pug puppy royal canin pug puppy food fawn pug puppy pug puppies for sale florida pug puppies for sale in Indiana pug puppies for sale in KY pug puppies for sale in NC pug dog puppy AKC Registered Pug Puppies For sale cheap pug puppies for sale near me cheap pug puppies for sale in California cheap pug puppies for sale in nj Black Pug Puppies for sale pugs puppies for sale
rahimhh21 · 12 weeks and 4 days ago
Pug Puppies for Sale Near Me pugs puppies for sale teacup pugs for sale pug puppies for sale by owner pug puppies ohio PUG PUPPY FOR SALE NEAR ME PUG PUPPIES FOR SALE pug puppies for sale in kentucky Pug Puppies for Sale Under $500 Near Me pug puppies for sale in texas pug puppies for sale $200 pugs for sale near me under $500 pugs for sale under $400 near me pugs for sale near me puppies for sale near me under $500 pug puppies for sale under $1,000 near me pug for sale pug puppies for sale under $300 Brindle Pug Pitbull Pug Mix Pugs for sale cheap Cheap pug affordable pug puppies for sale near me black pugs for sale near me White Pugs for sale pug dog for sale free pug puppies pug puppies for sale in my area mn pug breeders pug puppies indiana pugs for sale michigan PUG PUPPY ADOPTION Pug puppies for sale Pug puppies for sale near me Pug puppies near me Pug Puppies for Sale Under $500 Near Me USA USA USA USA USA USA Cute Pug Puppies Black pug puppies Black pug puppies for sale pug puppies for adoption black pug puppies for sale near me chihuahua pug mix puppies how much is a pug puppy teacup pug puppies baby pug puppies baby pug puppies for sale pictures of pug puppies pug puppies for sale in Ohio pug puppies price pug mix puppies teacup pug puppies for sale best food for pug puppy newborn pug puppies pug puppies craigslist pug puppies for sale craigslist adorable pug puppies how much does a pug puppy cost Pitbull pug mix puppies pug pit mix puppy pug puppies for sale $200 pug puppies for sale in NJ Pug puppies for sale in Wisconsin pug puppy cost pug puppy food royal canin pug puppy royal canin pug puppy food fawn pug puppy pug puppies for sale florida pug puppies for sale in Indiana pug puppies for sale in KY pug puppies for sale in NC pug dog puppy AKC Registered Pug Puppies For sale cheap pug puppies for sale near me cheap pug puppies for sale in California cheap pug puppies for sale in nj Black Pug Puppies for sale pugs puppies for sale
Perfecthomepugs · 3 weeks and 4 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: