{"id":2734,"date":"2019-10-29T05:05:40","date_gmt":"2019-10-29T05:05:40","guid":{"rendered":"http:\/\/www.incredigeek.com\/home\/?p=2734"},"modified":"2019-10-30T23:48:48","modified_gmt":"2019-10-30T23:48:48","slug":"linux-night-light-script","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/linux-night-light-script\/","title":{"rendered":"Linux night light script"},"content":{"rendered":"\n<p>The following script let you turn your screen brightness up\/down, but also adjust the color for night time.<\/p>\n\n\n\n<p>Copy and paste code below in a nightlight.sh file<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chmod +x nightlight.sh<\/pre>\n\n\n\n<p>and run<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.\/nightlight.sh on .5<\/pre>\n\n\n\n<p>Code:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/sh\nexport DISPLAY=$(w $(id -un) | awk 'NF > 7 &amp;&amp; $2 ~ \/tty[0-9]+\/ {print $3; exit}')\nPATH=\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin:\/usr\/games:\/usr\/local\/games\n\ndisplay=`<code><code>xrandr | grep \"\\ connected\" | cut -d\" \" -f1<\/code><\/code>`\nbrightness=\"$2\"\n# Check if brightness was specified.  If not, set screen to 50% brightness\nif (echo $2 | grep [0-9]);then\n         brightness=\"$2\"\nelif (echo $1 | grep -q help);then\n         echo \"############\"\nelse\n         brightness=\".5\"\n         echo \"Brightness variable not set, setting to fallback of 50%\"\nfi\nnight_mode() {\n   for disp in ${display}; do\n     xrandr --output $disp --gamma $1 --brightness ${brightness}\n  done }\n# auto is for future development\n# auto() {\n# The idea behind auto is to setup something that can pull the actual sunrise\/sunset times then automatically adjust the display.\n# Ideally there would be an algorithm so it does it slowly over a period of time, say slightly change the color over 30 minutes.\n# until the desired color limit is reached\n#\n# curl sunrise-sunset.com\/timezone\/time\n# if (time > sunset &amp;&amp; colorTemp != colorTempMin); then\n# set color to current temp-1\n# elif (time > sunrise &amp;&amp; colorTemp != colorTempMax); then);\n# set to full brightness and temp\n# else\n# unable to parse, skipping.\n# fi\n#}\n \nhelp() {\necho \" Help for nightmode script.  \nHow to run script\n.\/nightmode.sh on\/off brightness\nExamples: \nTurn nightmode on and set screen brightness to 75%\n.\/nightmode.sh on .75\nTurn night mode off and set screen brightness to 100%\n.\/nightmode.sh off 1\n\"\n}\ncase $1 in\n  off) night_mode 1:1:1 1.0 ;;\n  help) help ;;\n  auto) auto ;;\n  *) night_mode 1:1:0.5 ;;\nesac<\/pre>\n\n\n\n<p>Setup in crontab to automatically trigger when it gets night or morning<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">* 21 * * * ~\/nightlight.sh on .5  # Turn on at night\n* 7 * * * ~\/nightlight.sh off 1  # Turn off in the morning<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The following script let you turn your screen brightness up\/down, but also adjust the color for night time. Copy and paste code below in a nightlight.sh file chmod +x nightlight.sh and run .\/nightlight.sh on .5 Code: #!\/bin\/sh export DISPLAY=$(w $(id &hellip; <a href=\"https:\/\/www.incredigeek.com\/home\/linux-night-light-script\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,266],"tags":[211,772,771,173],"class_list":["post-2734","post","type-post","status-publish","format-standard","hentry","category-linux","category-scripts","tag-bash","tag-night-shift","tag-nightlight","tag-script"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/2734","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=2734"}],"version-history":[{"count":10,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/2734\/revisions"}],"predecessor-version":[{"id":2759,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/2734\/revisions\/2759"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=2734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=2734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=2734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}