Choose style:

Author Topic: Adjust the Brightness of your desktop display via Terminal  (Read 2943 times)

0 Members and 1 Guest are viewing this topic.

Offline zebedeeboss

  • Global Moderator
  • Hero
  • *****
  • Posts: 3045
  • Karma: 563
  • Life first... Peppermint a close 2nd :)
    • View Profile
  • Peppermint version(s): P10 / P9 Respin
Adjust the Brightness of your desktop display via Terminal
« on: June 19, 2016, 12:10:55 am »
Tired eyes at night… quickly alter your screen brightness with xrandr
In this small tutorial I will try and show you how to identify your monitor and how it is known by the OS.
Run a command in terminal to adjust the brightness to any level you like and how to restore to 100% default setting.
So the quick and easy terminal way is simply type into your terminal window
Code: [Select]
xrandr --output DP-0 --brightness 0.7
and press enter. Your brightness will alter
Where DP-0 is your monitor and 0.7 is how bright you want it. You can choose 0.8 or 0.5 or any number you like - only you will know what is comfortable for you.

To find out your monitor code, Open a terminal window (ctrl+alt+t) or find it in the menu and then when it is open

Type the following command
Code: [Select]
xrandr

and then press enter.  Now depending on the complexity of your graphics card you may have one entry or you may have many. Here is my output
Code: [Select]
zebedee @i7-peppermint7 ~ $ xrandr
Screen 0: minimum 8 x 8, current 3440 x 1440, maximum 16384 x 16384
DVI-I-0 disconnected (normal left inverted right x axis y axis)
DVI-I-1 disconnected (normal left inverted right x axis y axis)
HDMI-0 connected (normal left inverted right x axis y axis)
   1920x1080     60.00 +  59.94    50.00    29.97    25.00    23.97    60.05    60.00    50.04
   1680x1050     59.95
   1600x900      60.00
   1440x900      59.89
   1366x768      59.79
   1280x1024     75.02    60.02
   1280x800      59.81
   1280x720      60.00    59.94    50.00
   1152x864      75.00 
   1024x768      75.03    70.07    60.00
   800x600       75.00    72.19    60.32
   720x576       50.00    50.08
   720x480       59.94    60.05
   640x480       75.00    72.81    59.94
DP-0 connected primary 3440x1440+0+0 (normal left inverted right x axis y axis) 800mm x 340mm
   3440x1440     59.94*+  29.97
   1920x1080     60.00    59.94    50.00    60.00    50.04
   1720x1440     59.94
   1680x1050     59.95
   1440x900      59.89
   1280x1024     75.02    60.02
   1280x960      60.00
   1280x720      60.00    59.94    50.00
   1024x768      75.03    70.07    60.00
   800x600       75.00    72.19    60.32    56.25
   720x576       50.00
   720x480       59.94
   640x480       75.00    72.81    59.94    59.93
DP-1 disconnected (normal left inverted right x axis y axis)
DP-2 disconnected (normal left inverted right x axis y axis)
DP-3 disconnected (normal left inverted right x axis y axis)
DP-4 disconnected (normal left inverted right x axis y axis)
DP-5 disconnected (normal left inverted right x axis y axis)
zebedee@i7-peppermint7 ~ $
You should be able to work out which one you need to use to adjust the brightness.

for the example
Code: [Select]
DP-0 connected primary 3440x1440+0+0 (normal left inverted right x axis y axis) 800mm x 340mm
is the tell tale line to let you know you have a monitor attached as it shows the screen resolution

If the output you chose is not connected to an actual monitor you will get an error similar to
Code: [Select]
xrandr: Need crtc to set gamma on
when you try and run the brightness command

Simply go back and choose a diff output.  You will eventually get the right one and the screen will dimm.   you are doing NO harm by getting the command wrong. So don't worry.

To set it back to normal change 0.7 (or the figure you chose) to 1.0

Hopefully someone with more technical knowledge will come along and add to this post so that you can have keyboard shortcuts to the command and or a desktop icon to dimm / restore the display

Regards Zeb...
« Last Edit: February 23, 2017, 02:43:50 am by zebedeeboss »
Be Kind Whenever Possible...   It is Always Possible - Dalai Lama

Linux User #565092
P10 x64 Desktop - AMD Threadripper 2950X - 64Gb RAM - NVIDIA RTX2080Ti 11Gb - 2 x 27" 4k 3840x2160 - 1 x 34" 5120x2160
P9/10 @ P9 x64 Laptop - i7-7700HQ @ 2.80GHz - 8Gb RAM - Nvidia GTX1050 4Gb - 15.6" HD 1920x1080

Offline PCNetSpec

  • Administrator
  • Hero
  • *****
  • Posts: 25661
  • Karma: 2819
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
  • Peppermint version(s): Peppermint 8R, 9, and 9R
Re: Adjust the Brighness of your desktop display via Terminal
« Reply #1 on: June 19, 2016, 05:34:20 am »
Great tut Zeb, cheers :)
WARNING: You are logged into reality as 'root' .. logging in as 'insane' is the only safe option.

Team Peppermint
PCNetSpec

Offline Slim.Fatz

  • Trusted User
  • Veteran
  • *****
  • Posts: 1777
  • Karma: 469
  • Where's the mouse?
    • View Profile
  • Peppermint version(s): Peppermint 7, 8.5 & 10 - 64bit
Re: Adjust the Brighness of your desktop display via Terminal
« Reply #2 on: June 20, 2016, 01:00:47 am »
Hi zebedeeboss,

Thanks for the tutorial contribution! "Easy on the eyes" is something that is good for everyone.  ;)

Regards,

-- Slim
"Life first -- Peppermint a close 2nd!" -- Zeb

Tread lightly: Fluxbox, JWM, i3, Openbox, awesome

Offline Slim.Fatz

  • Trusted User
  • Veteran
  • *****
  • Posts: 1777
  • Karma: 469
  • Where's the mouse?
    • View Profile
  • Peppermint version(s): Peppermint 7, 8.5 & 10 - 64bit
Re: Adjust the Brighness of your desktop display via Terminal
« Reply #3 on: June 22, 2016, 02:39:28 pm »
Hi everyone,

This is a tutorial addendum


For those of you who have performed the steps in the original post (i.e. the first message in this thread) and now would like to change the brightness of your display using a keyboard shortcut rather than needing to always open a terminal to dim or undim the display then this "tutorial addendum" is for you.  ;)

The steps are easy to follow and you get to write an executable script (which might be something new for beginners -- Wow! Programming!!).  :o

To get started you should have successfully followed the steps in the original post, should know the designation of your display (DP-0 in the original post) and should have decided on a "dimming factor" (or "brightness factor") that you wish to use (e.g. like the 0.7 factor in the original post).

Given this knowledge we can begin writing our script file. Where you save this file on your system is your choice. Many people create a new folder in their home folder and cleverly name this new folder Scripts, where they store all of their scripts. So that is what I will do in this post as well. Any changes on your part are up to you;)

To begin, open the Nemo file manager -- e.g. by using the default keyboard shortcut <Control><Alt>f -- and create a new folder in your home folder named Scripts. Then, still in Nemo, open the Scripts folder and then press the F4 function key.

In the terminal window that opens type the following:

Code: [Select]
gedit display-dim.sh
and then press the Enter key. The text editor (gedit) will open with a new empty file that is named display-dim.sh.

Copy the following code and paste it into the empty display-dim.sh file:

Code: [Select]
#!/bin/sh

# display-dim.sh is a script to dim your display. The brightness
# factor is set to 0.7 (compared to full brightness which uses the
# factor 1.0).

xrandr --output DP-0 --brightness 0.7
If you prefer a different brightness factor (e.g. 0.55 for even more dimming or 0.85 for less dimming) then enter that factor in the file in place of 0.7. Also, be sure to use the actual designation of your display (unless, of course, your display is actually DP-0 -- on my notebook it is called eDP1).

Finally, save the file and close the text editor and the terminal window.

In Nemo you will see that your new script file display-dim.sh has been created in the Scripts folder. But it is not yet executable as a script program. To make it executable, position your mouse pointer on the file display-dim.sh and click the right-button of your mouse (or the left-button if your mouse is set up for left-handed use) to open the file's context menu. Select and click the bottom line (labelled: Properties) in this pop-up menu.

In the window that opens, click on the tab at the top named Permissions. Then go to the line labelled Execute and click in the empty checkbox Allow executing file as program. Finally, click on the button labelled Close.

Your script is now finished and is executable! Now you need to create a keyboard shortcut that will run the script when you wish to dim your display.

To do this, start the Peppermint Control Center by clicking on the main menu button on the desktop panel, then click on the top entry Peppermint Settings Panel. When it has started, open the Peppermint Control Center.

Now click on the tab at the top labelled Keyboard Shortcuts. Then click on the button in the upper right corner labelled Add New.

The window titled Add New Shortcut appears. Here you now enter the command to run your script in the empty text box. For the example we are using you enter this:

Code: [Select]
~/Scripts/display-dim.sh
and then click the OK button. The little window changes (the new title is Assign New Shortcut).

So decide on the keyboard shortcut that you wish to use to run your script -- let's say you wish to use <Alt>d as the shortcut. So click on the button at the top of this window labelled Alt and then click in the text box labelled Enter a valid character: and press the d key. Finally press the button labelled Apply. Your shortcut is finished and can be immediately used!  8)

But wait!! Wouldn't it be nice to also have a keyboard shortcut to return the display to full brightness again? Of course it would, so repeat all of the script writing steps above (just remember to use a different file name: e.g. you might use display-undim.sh). And in the new script file copy and paste this:

Code: [Select]
#!/bin/sh

# display-undim.sh is a script to set your display to full brightness.

xrandr --output DP-0 --brightness 1.0
After saving the new script and making it executable, create an appropriate keyboard shortcut to start it (e.g. <Alt>u).

That is the end of this tutorial addendum. I hope that you can follow it and that it works for you. If you have any problems, just ask back here and someone will gladly help you.

Regards,

-- Slim
« Last Edit: June 23, 2016, 01:49:02 am by Slim.Fatz »
"Life first -- Peppermint a close 2nd!" -- Zeb

Tread lightly: Fluxbox, JWM, i3, Openbox, awesome

Offline Timo

  • Member
  • ***
  • Posts: 163
  • Karma: 37
  • Open Source is more than the sum of its bytes
    • View Profile
  • Peppermint version(s): PM7 Respin (64bit) & PM8 (64bit)
Re: Adjust the Brighness of your desktop display via Terminal
« Reply #4 on: June 22, 2016, 03:46:33 pm »
Well done Slim & Zeb,
typing "writing script" in the search function shows this as well - and adjusting brightness is a really good example for a simple and usefull script :)

Offline PCNetSpec

  • Administrator
  • Hero
  • *****
  • Posts: 25661
  • Karma: 2819
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
  • Peppermint version(s): Peppermint 8R, 9, and 9R
Re: Adjust the Brighness of your desktop display via Terminal
« Reply #5 on: June 22, 2016, 07:27:35 pm »
Just a thought....

If nemo is controlling your desktop (default in Peppermint 6 and 7) If you put your known working scripts in
~/.local/share/nemo/scripts
(or symlink to them in there)

when you right-click the desktop, the scripts will be available in the context menu under "Scripts > <scriptname>[/color]"

« Last Edit: June 22, 2016, 07:33:42 pm by PCNetSpec »
WARNING: You are logged into reality as 'root' .. logging in as 'insane' is the only safe option.

Team Peppermint
PCNetSpec

Offline AndyInMokum

  • Global Moderator
  • Hero
  • *****
  • Posts: 4808
  • Karma: 1013
  • "Keep on Rockin' in the Free World"
    • View Profile
  • Peppermint version(s): PM 9 & PM 8 Respin-2 (64-bit)
Re: Adjust the Brighness of your desktop display via Terminal
« Reply #6 on: June 22, 2016, 09:32:30 pm »
Just a thought....

If nemo is controlling your desktop (default in Peppermint 6 and 7) If you put your known working scripts in
~/.local/share/nemo/scripts
(or symlink to them in there)

when you right-click the desktop, the scripts will be available in the context menu under "Scripts > <scriptname>[/color]"

That works really well.  It's so easy to forget how powerful Nemo is.  Symlinks Rock  8)!!
Backup! Backup! Backup! If you're missing any of these -  you ain't Backed Up!
For my system info please L/click HERE.

Offline PCNetSpec

  • Administrator
  • Hero
  • *****
  • Posts: 25661
  • Karma: 2819
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
  • Peppermint version(s): Peppermint 8R, 9, and 9R
Re: Adjust the Brighness of your desktop display via Terminal
« Reply #7 on: June 23, 2016, 01:04:37 am »
As do right-click context menu scripts .. I can see myself adding a ton of those :)
WARNING: You are logged into reality as 'root' .. logging in as 'insane' is the only safe option.

Team Peppermint
PCNetSpec

Offline Slim.Fatz

  • Trusted User
  • Veteran
  • *****
  • Posts: 1777
  • Karma: 469
  • Where's the mouse?
    • View Profile
  • Peppermint version(s): Peppermint 7, 8.5 & 10 - 64bit
Re: Adjust the Brighness of your desktop display via Terminal
« Reply #8 on: June 23, 2016, 01:47:04 am »
@PCNetSpec,

Thanks for that tip!! Didn't know about it, and it really works well. 8) (at least when I have Nemo controlling my desktop -- normally I have it set to not control the desktop, but I think most people leave it set to control the desktop)

@Timo,

Thank you, Timo. I'm glad that you enjoyed it. :)

Regards,

-- Slim
« Last Edit: June 23, 2016, 01:52:30 am by Slim.Fatz »
"Life first -- Peppermint a close 2nd!" -- Zeb

Tread lightly: Fluxbox, JWM, i3, Openbox, awesome

Offline PCNetSpec

  • Administrator
  • Hero
  • *****
  • Posts: 25661
  • Karma: 2819
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
  • Peppermint version(s): Peppermint 8R, 9, and 9R
Re: Adjust the Brighness of your desktop display via Terminal
« Reply #9 on: June 23, 2016, 02:03:10 am »
You're welcome Slim .. to tell the truth nemo/nautilus context menu script handling (as opposed to nemo/nautilus 'action' scripts .. which directly add actions to the context menu by file/folder type) was something I'd forgotten about and only recently rediscovered myself :)

You can bet I'll make more use of it in future versions of Peppermint though ;)

[EDIT]

In fact I can already feel ideas for a PM8 starting to 'gel' :)

<PCNetSpec waits for the American spelling police to say "shouldn't that be jell" and threaten to throw me in gaol :) >

<PCNetSpec also sits back and wonders how many will question why they'd want to force me to start saving footballs :)) >

<damnit, 'soccer' balls .. this is getting ridiculous ::) >

<runs off to check with Miriam the Web Star they don't spell 'ridiculous' differently :-\ >
« Last Edit: June 23, 2016, 02:58:15 am by PCNetSpec »
WARNING: You are logged into reality as 'root' .. logging in as 'insane' is the only safe option.

Team Peppermint
PCNetSpec

Offline AndyInMokum

  • Global Moderator
  • Hero
  • *****
  • Posts: 4808
  • Karma: 1013
  • "Keep on Rockin' in the Free World"
    • View Profile
  • Peppermint version(s): PM 9 & PM 8 Respin-2 (64-bit)
Re: Adjust the Brighness of your desktop display via Terminal
« Reply #10 on: June 23, 2016, 02:57:37 am »

<PCNetSpec waits for the American spelling police to say "shouldn't that be jell" and threaten to throw me in gaol :) >
Or as George W Bush would probably say, coalessiate  ;).
Backup! Backup! Backup! If you're missing any of these -  you ain't Backed Up!
For my system info please L/click HERE.

Offline PCNetSpec

  • Administrator
  • Hero
  • *****
  • Posts: 25661
  • Karma: 2819
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
  • Peppermint version(s): Peppermint 8R, 9, and 9R
Re: Adjust the Brighness of your desktop display via Terminal
« Reply #11 on: June 23, 2016, 03:00:49 am »
Ouch .. LOL :))

Then go back to the blackboard and change the 'c' to a 'k' ?
« Last Edit: June 23, 2016, 03:11:31 am by PCNetSpec »
WARNING: You are logged into reality as 'root' .. logging in as 'insane' is the only safe option.

Team Peppermint
PCNetSpec

Offline zebedeeboss

  • Global Moderator
  • Hero
  • *****
  • Posts: 3045
  • Karma: 563
  • Life first... Peppermint a close 2nd :)
    • View Profile
  • Peppermint version(s): P10 / P9 Respin
Re: Adjust the Brighness of your desktop display via Terminal
« Reply #12 on: June 23, 2016, 07:55:04 am »
Ouch .. LOL

Then go back to the blackboard and change the 'c' to a 'k' ?
:o "Chalkboard"   Pulllleeeeeaaaassseeeeeeee
Be Kind Whenever Possible...   It is Always Possible - Dalai Lama

Linux User #565092
P10 x64 Desktop - AMD Threadripper 2950X - 64Gb RAM - NVIDIA RTX2080Ti 11Gb - 2 x 27" 4k 3840x2160 - 1 x 34" 5120x2160
P9/10 @ P9 x64 Laptop - i7-7700HQ @ 2.80GHz - 8Gb RAM - Nvidia GTX1050 4Gb - 15.6" HD 1920x1080

Offline PCNetSpec

  • Administrator
  • Hero
  • *****
  • Posts: 25661
  • Karma: 2819
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
  • Peppermint version(s): Peppermint 8R, 9, and 9R
Re: Adjust the Brighness of your desktop display via Terminal
« Reply #13 on: June 23, 2016, 09:07:32 am »
LOL :))
WARNING: You are logged into reality as 'root' .. logging in as 'insane' is the only safe option.

Team Peppermint
PCNetSpec