Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Script/Action to Dim Screen based on time of day

  1. #1
    Low Bitrate thanassius's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    83

    Script/Action to Dim Screen based on time of day

    A few months back, I had the idea to use an Apple Script or Automator Workflow to check the system time, and automatically dim the screen at a certain time each day. This way the screen wouldn't be blindingly bright at night, but would be at full brightness during the day.

    My idea was to have the code check the system time, and at say, 7pm, take the brightness down a few notches. On the flip side, anytime between say 6am and 6:59pm, it would adjust back to full brightness.

    I don't really know any Applescript. I tried recording an action (like a macro in MS office) but that didn't work. I was also unsuccessful at creating an Automator Workflow to accomplish this (I can't get Automator to allow access to things in System Prefs). I've tried searching to see if someone already did this, but I haven't had any luck. Is this even possible? Is the Mac Mini capable of adjusting the dimness of an external display (meaning, can this type of thing only be done on a notebook)? Thanks for any help anyone can provide!

  2. #2
    AMP Creator aychamo's Avatar
    Join Date
    Jun 2006
    Posts
    493
    You know, I think I looked into this too. I think from what I found the only real way was to "stuff" the keyboard buffer (or whatever) with the right key-combo to dim the screen (ie, Fn-F1 or Fn-F2). It sures seems like there should be an easier way.

    I have no idea if external displays can be dimmed either. I only have a notebook. I gave my dad a MacMini for Christmas to replace his fried Dell, so maybe I can give him a ring and see if he can dim the monitor, etc.
    -

  3. #3
    Low Bitrate thanassius's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    83
    I know, you'd think someone else would need this functionality. What exactly do you mean by stuffing the key combination? Into an applescript? My coding skills aren't the greatest in general, and they're virtually non-existent on a Mac.

    The Mac Mini that's going in my car is on my desk at home next to my PowerBook, so I can check as well. I think I did this a few months back, and I *think* it's not even an option on the Mini. My guess is that OS X detects what hardware it's being installed on and enables this feature accordingly. If that is in fact the case, maybe there's some way to trick it into thinking the Mini is notebook (but then there's the whole issue of whether or not the touch screen will respond if we tell it to dim).

  4. #4
    QCar Creator Jirka Jirout's Avatar
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    590
    Not sure about how to do this in AppleScript and Automator or whether it is possible at all, but this thing is relatively easy otherwise. All you need to do is to adjust the gamma of the screen. An example from my code:

    Code:
    - (void) setNiteVision:(BOOL)niteVisionState {
    	if (niteVisionState){
    		// engage the nite vision by changing the screen gamma value
    		// the values (which determine the color an brightness) are
    		// taken from the module's setup where they are stored as NSNumbers
    		CGGammaValue gamma, min;
    		CGDisplayErr err;
    
    		min = 0.1;
    		float redMax = [[moduleSetup objectForKey:@"RED_GAMMA"] floatValue];
    		float greenMax = [[moduleSetup objectForKey:@"GREEN_GAMMA"] floatValue];
    		float blueMax = [[moduleSetup objectForKey:@"BLUE_GAMMA"] floatValue];
    		gamma = 1.0; // we do not want to change the curve, just adjust end points
    	
    		err = CGSetDisplayTransferByFormula(
    			CGMainDisplayID(),
    			min, redMax, 1, // red
    			min, greenMax, 1, // green
    			min, blueMax, 1); // blue
    	}
    	else
    	// restore the default gamma curve as defined in the system
    	// preferences for all displays
    	CGDisplayRestoreColorSyncSettings();
    }

  5. #5
    Maximum Bitrate pepsibobby's Avatar
    Join Date
    Dec 2005
    Location
    Kaiserslautern Germany
    Posts
    648
    i want the app pease.
    Cant code cause I dont know how, but give me the paint bucket and my eraser and have at you!

  6. #6
    Admin. Linux loser.
    Auto Apps:loading...
    Bugbyte's Avatar
    Join Date
    Sep 2004
    Location
    Corning, NY
    Posts
    7,364
    Blog Entries
    2
    Following is an Applescript handler that use GUI scripting to control the Display preference pane. I presume if your screen does not have a "Brightness" slider that this script will error. It works fine on my Apple studio display but I haven't tested it on the Xenarc.

    Cut and paste the code below the dashes and run it in applescript studio to try it out. If it works, save one Applescript with the dim value and save a different one with the bright value. You should be able to dim/bright by running the appropriate script.

    ------------------------------------------------------------

    ChangeBrightness(.5) --Set this value between 0 and 1 to adjust brightness

    on ChangeBrightness(BrightnessValue)

    tell application "System Preferences"
    --activate
    set current pane to pane "com.apple.preference.displays"
    end tell
    tell application "System Events" to tell process "System Preferences"

    tell radio button "Display" of tab group 1 of window 1 to if value is 0 then
    repeat until value is 1
    click
    end repeat
    end if


    tell slider 1 of group 2 of tab group 1 of window 1 to set value to BrightnessValue
    end tell
    --tell application "System Preferences" to quit
    end ChangeBrightness
    Quote Originally Posted by ghettocruzer View Post
    I was gung ho on building a PC [until] just recently. However, between my new phone having internet and GPS and all...and this kit...Im starting to have trouble justfiying it haha.
    Want to:
    -Find out about the new iBug iPad install?
    -Find out about carPC's in just 5 minutes? View the Car PC 101 video

  7. #7
    Low Bitrate thanassius's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    83
    Thanks Bugbyte, I tried it on my Powerbook and it works great! I'll try it on the Mini tomorrow as well. One question though, is there any code that can be added to make everything hidden as it works? Currently you see the Displays pref pane opening and adjusting, and then it remains open when the script has finished running. Can all that be done in the background? Thanks!

  8. #8
    Admin. Linux loser.
    Auto Apps:loading...
    Bugbyte's Avatar
    Join Date
    Sep 2004
    Location
    Corning, NY
    Posts
    7,364
    Blog Entries
    2
    I can't quite get every bit of it to be invisible, but here's a script that does it and only shows the display window briefly, then closes the prefs window.

    ChangeBrightness(1) --Set this value between 0 and 1 to adjust brightness

    on ChangeBrightness(BrightnessValue)

    tell application "System Preferences"
    launch without visibles
    set current pane to pane "com.apple.preference.displays"
    end tell
    tell application "System Events" to tell process "System Preferences"

    tell radio button "Display" of tab group 1 of window 1 to if value is 0 then
    repeat until value is 1
    click
    end repeat
    end if
    tell slider 1 of group 2 of tab group 1 of window 1 to set value to BrightnessValue
    end tell
    tell application "System Preferences" to quit
    end ChangeBrightness
    Quote Originally Posted by ghettocruzer View Post
    I was gung ho on building a PC [until] just recently. However, between my new phone having internet and GPS and all...and this kit...Im starting to have trouble justfiying it haha.
    Want to:
    -Find out about the new iBug iPad install?
    -Find out about carPC's in just 5 minutes? View the Car PC 101 video

  9. #9
    Raw Wave shotgunefx's Avatar
    Join Date
    Apr 2005
    Location
    Boston, MA
    Posts
    1,800
    Don't know if this is helpful or not, I have a perl script here that's meant to run from cron every X minutes and do something depending on if it's night or day.

    The fleshed out version on my system uses xbrightness to change the gamma in X. (Though it checks to see if a net cable is plugged in first, then it acts like it's always day because I'm in the house).

    I know OSX is based on BSD, but I know nothing about the windowing system.

  10. #10
    Low Bitrate thanassius's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    83
    Thanks Bugbyte! The revised code works very well. All that shows is the system prefs window for a second or two, but for my needs that's acceptable. Now I just have to test it on the Mini connected to the Xenarc.

    Shotgun, I saved Bug's script as an applicatoin and I'm going to work with automator to run it at specific times of the day, but thanks for your post.

Page 1 of 2 12 LastLast

Similar Threads

  1. Touch Screen Based Gesture Interface?
    By Lazyflip in forum Software & Software Development
    Replies: 13
    Last Post: 01-25-2006, 03:28 PM
  2. Dim LCD based on ambient light
    By neon_eddy in forum LCD/Display
    Replies: 3
    Last Post: 12-01-2005, 08:02 AM
  3. Request: Time based gamma control.
    By TRONiC in forum Centrafuse
    Replies: 2
    Last Post: 09-20-2005, 08:16 PM
  4. Replies: 6
    Last Post: 10-20-2004, 03:30 AM
  5. Replies: 13
    Last Post: 07-02-2002, 11:54 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •