You are not logged in.

#1 2012-09-22 15:30:54

Haikarainen
Member
Registered: 2012-09-04
Posts: 90

LightScript - Lightweight script to easily change screen brightness.

Wiki: https://wiki.archlinux.org/index.php/LightScript
AUR: https://aur.archlinux.org/packages.php?ID=62997
Official site: http://haikarainen.dotgeek.org/lightscript/

screenshot.png

My first package, be gentle smile
Created this script because of 3 reasons:
1. KDE's controller for backlight is really buggy for me, makes it unusable.
2. xbacklight does not work well with multiple controllers for the same device (I get 7 stages of resolution instead of 4882).
3. I like scripting/doing my own work.

What it does?
LightScript automatically detects the best backlight-controller based off its precision/resolution, and uses that controller to set the backlight to a value you specify in percent.
Example: "light 30" <- Set brightness to 30%

If sudo is installed, it will attempt to use this instead of forcing root (so you wont have to type "sudo light x" instead of just "light x").
It also has a default minimum-cap of 5%, since some controllers turn the display pitchblack on 0%. This behaviour can be overridden by changing /etc/lightscript/minlight

Updates:
Since version 0.3.6 the script now also takes + and - operators, so you can increase and decrease brightness instead of just giving a fixed value.
It also checks for filepermissions on controllers before deciding wether to force root/use sudo etc.
Example: "light 10+" <- Increase brightness by 10%

0.3.6 also came with 2 small issues that is on my todolist; Firstly, typing "light +" or "light -" will give expr errors, nothing dangerous though. Secondly, the output on dynamic changes(with operators) might shift with 1-2% when mixed with regular changes. This is only what you see though, internally everything works fine, it will still write the correct values to the controllers.

Since version 0.3.5 the script has undergone huge internal changes (basically rewrote big parts of the script to make it more consistant and futuresafe, removed dependencies, gave a prettier output as well as more information etc)


Find any bugs? Have any feedback? Dont hesitate to reply smile

PS. I am aware that this might not be preferrable to most people (if xbacklight/other software they use works well), I just want to share my work with the community (especially since it is my first real bash script, also I get to practice AUR-packaging for upcoming c++-made-software!)

Last edited by Haikarainen (2012-10-01 17:50:18)

Offline

#2 2012-09-22 20:01:51

Shinryuu
Member
From: 俺のコスモス
Registered: 2010-02-27
Posts: 338

Re: LightScript - Lightweight script to easily change screen brightness.

Oh, this looks pretty easy to use and it's nice you filled information in to Wiki as well. I'll test it with my laptop when I next time launch it up wink I wonder if this thread can be moved to "Community Contributions" section, I believe administrators will do that if necessary.

Also, Hi from Finland.

Last edited by Shinryuu (2012-09-22 20:02:09)

Offline

#3 2012-09-22 20:19:00

Haikarainen
Member
Registered: 2012-09-04
Posts: 90

Re: LightScript - Lightweight script to easily change screen brightness.

Shinryuu wrote:

Oh, this looks pretty easy to use and it's nice you filled information in to Wiki as well. I'll test it with my laptop when I next time launch it up wink I wonder if this thread can be moved to "Community Contributions" section, I believe administrators will do that if necessary.

Also, Hi from Finland.

Thanks, appreciate the feedback! I thought about that myself, but I found 3 different places to post this on the forum (1 was the contributions, 1 here, and 1 in the sticky for small programs). We'll see what the mods think, hopefully they have mercy upon my soul and doesn't delete the whole post.

Hi Finland / Sweden (Only 50% finnish, not a native speaker)

Offline

#4 2012-09-24 20:34:14

Haikarainen
Member
Registered: 2012-09-04
Posts: 90

Re: LightScript - Lightweight script to easily change screen brightness.

New version!

Changelog:

        * Rewrote most parts of the script to be consistent and future-safe
        * Added a more verbose output to give enduser more information, as well as coloring for ease of focus
        * Removed 'bc' as dependency
        * Added/improved functionality overall
        * minlight is now in the backuparray and should not be overwritten on upgrades

Offline

#5 2012-09-27 05:25:45

archie0
Member
Registered: 2012-02-26
Posts: 144

Re: LightScript - Lightweight script to easily change screen brightness.

Sadly, it asks for the root password when running without sudo.

Offline

#6 2012-09-27 06:23:12

illusionist
Member
From: localhost
Registered: 2012-04-03
Posts: 498

Re: LightScript - Lightweight script to easily change screen brightness.

@ fredrik Haikarainen
very good work mate. You made a useful piece of program. I appreciate your efforts. keep up the good work .

@archie0
that is not the case with me , maybe the maintainer fixed that in the new version , are you in the 'video' group if not try doing that.


  Never argue with stupid people,They will drag you down to their level and then beat you with experience.--Mark Twain
@github

Offline

#7 2012-09-27 19:08:29

Haikarainen
Member
Registered: 2012-09-04
Posts: 90

Re: LightScript - Lightweight script to easily change screen brightness.

archie0 wrote:

Sadly, it asks for the root password when running without sudo.

Care to elaborate? What output do you get and what is the command you issue?

Do you mean without sudo installed, or without sudo issued in the commandline?

The expected behaviour is like this; If you have sudo installed, just type "light 20" and it will automatically append sudo in the command (so it asks for your password only if the current sudo session is timed out). If you do not have sudo installed and is a regular user, it will complain about needing root.

Offline

#8 2012-09-27 19:09:07

Haikarainen
Member
Registered: 2012-09-04
Posts: 90

Re: LightScript - Lightweight script to easily change screen brightness.

illusionist wrote:

@ fredrik Haikarainen
very good work mate. You made a useful piece of program. I appreciate your efforts. keep up the good work .

Thank you!

Offline

#9 2012-09-28 05:07:44

archie0
Member
Registered: 2012-02-26
Posts: 144

Re: LightScript - Lightweight script to easily change screen brightness.

So, sudo is installed. If I run the command without admin rights (eg. light 20), it asks me for the password. I think this could be easily bypassed if I tweak my sudoers file (eg. NOPASSWD: ALL)

Offline

#10 2012-09-28 12:39:22

Haikarainen
Member
Registered: 2012-09-04
Posts: 90

Re: LightScript - Lightweight script to easily change screen brightness.

archie0 wrote:

So, sudo is installed. If I run the command without admin rights (eg. light 20), it asks me for the password. I think this could be easily bypassed if I tweak my sudoers file (eg. NOPASSWD: ALL)


Err, that is the expected behaviour with sudo. I would NOT recommend changing sudo so that it does not require a password, you might as well login as root instead.

What I can do, which I have also been thinking about doing, is checking writepermissions on the controller files before checking if needing root, that way you can just change the filepermissions on the controllers instead. I'll let you know when/if this is implemented.

Offline

#11 2012-09-30 16:07:35

4nti7rust
Member
Registered: 2012-08-15
Posts: 4

Re: LightScript - Lightweight script to easily change screen brightness.

I love it ! Thanks, everything is working perfectly for me.

Offline

#12 2012-09-30 22:33:20

illusionist
Member
From: localhost
Registered: 2012-04-03
Posts: 498

Re: LightScript - Lightweight script to easily change screen brightness.

@ Haikarainen
feature request :   can you make it take the '+' or '-' operators with the number argument like we do with alsa.
example: light 20+ , light 20-

so that it can be bound to the keys easily.


  Never argue with stupid people,They will drag you down to their level and then beat you with experience.--Mark Twain
@github

Offline

#13 2012-10-01 13:05:38

Haikarainen
Member
Registered: 2012-09-04
Posts: 90

Re: LightScript - Lightweight script to easily change screen brightness.

illusionist wrote:

@ Haikarainen
feature request :   can you make it take the '+' or '-' operators with the number argument like we do with alsa.
example: light 20+ , light 20-

so that it can be bound to the keys easily.

I will look into it. This feature might mean I'll have to save the best controller somewhere to get the real current brightness, although they shouldn't change.

EDIT:
Allright nevermind, the actual_brightness-file contains the actual brightness bound to all controllers, will probably implement this feat sometime today/tomorrow!

EDIT2: Reminder to myself; Add permissionchecks before requesting sudo/root while youre at it

Last edited by Haikarainen (2012-10-01 13:28:57)

Offline

#14 2012-10-01 17:53:15

Haikarainen
Member
Registered: 2012-09-04
Posts: 90

Re: LightScript - Lightweight script to easily change screen brightness.

illusionist wrote:

@ Haikarainen
feature request :   can you make it take the '+' or '-' operators with the number argument like we do with alsa.
example: light 20+ , light 20-

so that it can be bound to the keys easily.


Done, check latest version 0.3.6

Offline

#15 2012-10-01 19:28:35

illusionist
Member
From: localhost
Registered: 2012-04-03
Posts: 498

Re: LightScript - Lightweight script to easily change screen brightness.

That was fast...
Thanks it is much easier now.


  Never argue with stupid people,They will drag you down to their level and then beat you with experience.--Mark Twain
@github

Offline

#16 2012-10-01 21:06:39

Haikarainen
Member
Registered: 2012-09-04
Posts: 90

Re: LightScript - Lightweight script to easily change screen brightness.

illusionist wrote:

That was fast...
Thanks it is much easier now.

Heh well I've been thinking about implementing it myself before, since I wanted that exact functionality. Now I have smile

Offline

#17 2012-10-03 23:35:24

codelinx
Member
Registered: 2012-09-08
Posts: 4

Re: LightScript - Lightweight script to easily change screen brightness.

OMG thank you thank you, i have never been able to get my backlight working on any distro with any kernel, and i have been ashamed to ask how and just have read nonsense. This is amazing, I have an Acer 5742 w/ an i5.

EDIT:
Maybe adding a current status option for the backlight like "light state" or "light now" for the current percent or # in the range, just an idea.

Last edited by codelinx (2012-10-03 23:37:39)

Offline

#18 2012-10-04 00:31:22

moetunes
Member
From: A comfortable couch
Registered: 2010-10-09
Posts: 1,017

Re: LightScript - Lightweight script to easily change screen brightness.

codelinx wrote:

OMG thank you thank you, i have never been able to get my backlight working on any distro with any kernel, and i have been ashamed to ask how and just have read nonsense. This is amazing, I have an Acer 5742 w/ an i5.

There a wiki entry for that laptop that tells how to have the backlight adjustable.
HTH


You're just jealous because the voices only talk to me.

Offline

#19 2012-10-16 15:44:53

Haikarainen
Member
Registered: 2012-09-04
Posts: 90

Re: LightScript - Lightweight script to easily change screen brightness.

codelinx wrote:

OMG thank you thank you, i have never been able to get my backlight working on any distro with any kernel, and i have been ashamed to ask how and just have read nonsense. This is amazing, I have an Acer 5742 w/ an i5.

EDIT:
Maybe adding a current status option for the backlight like "light state" or "light now" for the current percent or # in the range, just an idea.


Glad I could be of help! smile

I've been thinking about it, right now I'd have to restructure bigger parts of the script to implement that functionality, or else the scriptsource would become too sloppy for me to maintain.

I've also been thinking about turning this into a C/C++-project, making it an executable. What do you guys think about this?

Offline

#20 2012-10-16 18:05:42

illusionist
Member
From: localhost
Registered: 2012-04-03
Posts: 498

Re: LightScript - Lightweight script to easily change screen brightness.

Haikarainen wrote:

I've also been thinking about turning this into a C/C++-project, making it an executable. What do you guys think about this?

Writing the script in "C" is a nice idea from the portability's  point of view.


  Never argue with stupid people,They will drag you down to their level and then beat you with experience.--Mark Twain
@github

Offline

#21 2012-10-17 12:08:40

Haikarainen
Member
Registered: 2012-09-04
Posts: 90

Re: LightScript - Lightweight script to easily change screen brightness.

illusionist wrote:
Haikarainen wrote:

I've also been thinking about turning this into a C/C++-project, making it an executable. What do you guys think about this?

Writing the script in "C" is a nice idea from the portability's  point of view.

Indeed, I am currently having issues deciding wether I'm gonna go with ANSI C 89/99, or C++.

ANSI C would make it uberportable, but it would be way harder to code and maintain.

C++ would be way easier to code and maintain since I can do it truly objectoriented with classes and namespaces (at least for me, this way of work is a big deal in my career and what I'm used to do). But it wouldnt have the same portability.

Offline

#22 2012-10-17 12:23:43

illusionist
Member
From: localhost
Registered: 2012-04-03
Posts: 498

Re: LightScript - Lightweight script to easily change screen brightness.

Haikarainen wrote:

ANSI C would make it uberportable, but it would be way harder to code and maintain.

C++ would be way easier to code and maintain since I can do it truly objectoriented with classes and namespaces (at least for me, this way of work is a big deal in my career and what I'm used to do). But it wouldnt have the same portability.

Going with 'C' is just my humble opinion. Afterall you are the maintainer and if you find yourself comfortable with C++ OOP , it is your choice. The user only needs the functionality . Either way is good to go. smile


  Never argue with stupid people,They will drag you down to their level and then beat you with experience.--Mark Twain
@github

Offline

#23 2012-10-18 23:20:24

s0l1dsnak3123
Member
From: Scotland
Registered: 2008-06-26
Posts: 62
Website

Re: LightScript - Lightweight script to easily change screen brightness.

I'd like to point out that this script seems to be the only one that works with a 2011 27" imac. Thank you so much.

Offline

#24 2012-10-19 10:47:04

Haikarainen
Member
Registered: 2012-09-04
Posts: 90

Re: LightScript - Lightweight script to easily change screen brightness.

s0l1dsnak3123 wrote:

I'd like to point out that this script seems to be the only one that works with a 2011 27" imac. Thank you so much.

Oh wow big_smile That is really cool! You're welcome I guess smile

Offline

#25 2012-10-22 18:10:25

Haikarainen
Member
Registered: 2012-09-04
Posts: 90

Re: LightScript - Lightweight script to easily change screen brightness.

The script has been successfully ported to an ANSI C89-program!

Its commandline options is really different from lightscripts,  but internally it works the same way. I've also added functionality per requests I've gotten, I'll let the programs output speak for itself:

fredrik@fredrik-arch ~/projects/light % ./light                                                                                                                  [20:07:53]
Usage: light [-qcas] <value>

        -q:      Run quiet, supresses output.
        -c:      Prints the current brightness in percent and exits.(Not precise)
        -p:      Prints the current brightness directly from controller and exits. (Precise)
        -m:      Prints the max brightness directly from controller and exits. (To be used side-by-side with -p)
        -a:      Add the value instead of setting it.
        -s:      Subtract the value instead of setting it.

        <value>  Brightness wanted in percent.

I'll package this under a different name tomorrow(since it's now a completely different product), stay tuned!

Offline

Board footer

Powered by FluxBB