Sponsored links

Go Back   MP3Car.com > Mp3Car Technical > MacCar


Reply
 
Share Thread Tools Display Modes
Old 07-18-2006, 10:29 AM   #1
Low Bitrate
 
thanassius's Avatar
 
Join Date: Apr 2006
Location: Maryland
Posts: 83
thanassius is on a distinguished road
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!
thanassius is offline   Reply With Quote
Advertisement
 
Advertisement
Sponsored links

Old 07-18-2006, 11:31 AM   #2
AMP Creator
 
aychamo's Avatar
 
Join Date: Jun 2006
Posts: 454
aychamo is on a distinguished road
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.
__________________
-
aychamo is offline   Reply With Quote
Old 07-18-2006, 12:59 PM   #3
Low Bitrate
 
thanassius's Avatar
 
Join Date: Apr 2006
Location: Maryland
Posts: 83
thanassius is on a distinguished road
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).
thanassius is offline   Reply With Quote
Old 07-19-2006, 02:49 PM   #4
QCar Creator
 
Jirka Jirout's Avatar
 
Join Date: Jul 2005
Location: Netherlands
Posts: 577
Jirka Jirout is on a distinguished road
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(); }

Jirka Jirout is offline   Reply With Quote
Old 07-19-2006, 05:53 PM   #5
Maximum Bitrate
 
pepsibobby's Avatar
 
Join Date: Dec 2005
Location: Langley AFB
Posts: 607
pepsibobby is on a distinguished road
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!
pepsibobby is offline   Reply With Quote
Old 07-19-2006, 10:05 PM   #6
Admin. Don't bug or I'll byte.
 
Bugbyte's Avatar
 
Join Date: Sep 2004
Location: Corning, NY
Posts: 6,143
Bugbyte is a splendid one to beholdBugbyte is a splendid one to beholdBugbyte is a splendid one to beholdBugbyte is a splendid one to beholdBugbyte is a splendid one to beholdBugbyte is a splendid one to beholdBugbyte is a splendid one to behold
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
__________________
Want to:
-Find out about the iBug?
-Stop being a newbie? Take a look at the FAQ Emporium?
-Find out about carPC's in just 5 minutes? View the Car PC 101 video
-Help me kill my car PC
-Watch live video streams from my mobile PC? Check it out here.
-Where is the iBug?
Bugbyte is offline   Reply With Quote
Old 07-20-2006, 10:38 PM   #7
Low Bitrate
 
thanassius's Avatar
 
Join Date: Apr 2006
Location: Maryland
Posts: 83
thanassius is on a distinguished road
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!
thanassius is offline   Reply With Quote
Old 07-21-2006, 04:50 PM   #8
Admin. Don't bug or I'll byte.
 
Bugbyte's Avatar
 
Join Date: Sep 2004
Location: Corning, NY
Posts: 6,143
Bugbyte is a splendid one to beholdBugbyte is a splendid one to beholdBugbyte is a splendid one to beholdBugbyte is a splendid one to beholdBugbyte is a splendid one to beholdBugbyte is a splendid one to beholdBugbyte is a splendid one to behold
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
__________________
Want to:
-Find out about the iBug?
-Stop being a newbie? Take a look at the FAQ Emporium?
-Find out about carPC's in just 5 minutes? View the Car PC 101 video
-Help me kill my car PC
-Watch live video streams from my mobile PC? Check it out here.
-Where is the iBug?

Last edited by Bugbyte; 07-21-2006 at 05:00 PM.
Bugbyte is offline   Reply With Quote
Sponsored links
Advertisement
 
Advertisement
Old 07-21-2006, 04:58 PM   #9
Raw Wave
 
shotgunefx's Avatar
 
Join Date: Apr 2005
Location: Boston, MA
Posts: 1,800
shotgunefx is on a distinguished road
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.
shotgunefx is offline   Reply With Quote
Old 07-22-2006, 12:58 PM   #10
Low Bitrate
 
thanassius's Avatar
 
Join Date: Apr 2006
Location: Maryland
Posts: 83
thanassius is on a distinguished road
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.
thanassius is offline   Reply With Quote
Old 07-22-2006, 01:18 PM   #11
Low Bitrate
 
thanassius's Avatar
 
Join Date: Apr 2006
Location: Maryland
Posts: 83
thanassius is on a distinguished road
Ok so nevermind Automator, I resaved them as scripts, then created an event in iCal that repeats everyday at a specified time, and I set the alarm to Run Script. Still ahve to test on the mini though.
thanassius is offline   Reply With Quote
Old 03-17-2007, 03:35 AM   #12
Low Bitrate
 
thanassius's Avatar
 
Join Date: Apr 2006
Location: Maryland
Posts: 83
thanassius is on a distinguished road
I'm about to resurrect an old thread, in hopes of putting it to bed for good! I took my install off of the indefinite hold it's been on for almost a year, and I just had some new thoughts on this issue...

Bugbyte's AppleScripts mentioned above work great for an Apple notebook or cinema display, but unfortunatly have no effect on the touchscreens most of us are using. However, using Shades, you can adjust the screen brightness of any display connected to any Mac, as the adjustment is not dependant on any specific type of hardware. It also has the ability to assign hot keys to increase and decrease brightness functions.

As I mentioned earlier, I have no coding skills at all, SO, would someone be willing to write up an AppleScript similar to Bugbyte's that opens Shades (if its not already running) and sends the hot key combinations to it? Shades can run hidden in the background (in its preferences, keep it out of the dock and the menu bar), and we can set the resulting Apple Script as a reccuring iCal alarm, to seamlessly automate the process of dimming and brightening our touchscreens at predetermined times of the day.

I would be totally thrilled if someone would be able to do this! Thanks in advance :-)

Last edited by thanassius; 03-17-2007 at 03:41 AM. Reason: clarifying a bit
thanassius is offline   Reply With Quote
Old 03-17-2007, 03:23 PM   #13
Admin. Don't bug or I'll byte.
 
Bugbyte's Avatar
 
Join Date: Sep 2004
Location: Corning, NY
Posts: 6,143
Bugbyte is a splendid one to beholdBugbyte is a splendid one to beholdBugbyte is a splendid one to beholdBugbyte is a splendid one to beholdBugbyte is a splendid one to beholdBugbyte is a splendid one to beholdBugbyte is a splendid one to behold
I suggested this idea in the Amp wishlist thread but I don't think people took it seriously. I like this implementation. It should be a snap to write a script.

For awhile, I looked into trying to calculate sunrise/sunset based on a user's lat/long but Applescript doesn't have the math functions to do it. You end up having to call them out of Coccoa! The iCal alarm idea is a dead simple solution for that problem.

I'll look at it but no promises on time frames.
__________________
Want to:
-Find out about the iBug?
-Stop being a newbie? Take a look at the FAQ Emporium?
-Find out about carPC's in just 5 minutes? View the Car PC 101 video
-Help me kill my car PC
-Watch live video streams from my mobile PC? Check it out here.
-Where is the iBug?
Bugbyte is offline   Reply With Quote
Old 03-17-2007, 04:17 PM   #14
QCar Creator
 
Jirka Jirout's Avatar
 
Join Date: Jul 2005
Location: Netherlands
Posts: 577
Jirka Jirout is on a distinguished road
http://www.srrb.noaa.gov/highlights/sunrise/azel.html

Check the source of the page for JavaScript implementation of the algorithm that calculates the position of sun. And I am sure there are plenty of other sites and libraries. AFAIK it does not require any math, that is not doable in AppleScript.
Jirka Jirout is offline   Reply With Quote
Old 03-17-2007, 04:22 PM   #15
Admin. Don't bug or I'll byte.
 
Bugbyte's Avatar
 
Join Date: Sep 2004
Location: Corning, NY
Posts: 6,143
Bugbyte is a splendid one to beholdBugbyte is a splendid one to beholdBugbyte is a splendid one to beholdBugbyte is a splendid one to beholdBugbyte is a splendid one to beholdBugbyte is a splendid one to beholdBugbyte is a splendid one to behold
Try this

This worked on my Mini with Shades installed.

There's no error handling in it. It assumes Shades is running. It then checks to see if it is either before or after 12:00pm. If it is after 12:00pm, it dims. If it is before 12:00pm, it brightens.

It sends 10 repeats of Cmd and '-' or 10 repeats of Cmd and '+'. Make sure your hotkeys are set to this setting.

You can easily modify how many times it repeats by opening the script in Script Editor and changing the number in the "repeat" lines. There are two.
Attached Files
File Type: zip ShadesDimmer.zip (19.1 KB, 72 views)
__________________
Want to:
-Find out about the iBug?
-Stop being a newbie? Take a look at the FAQ Emporium?
-Find out about carPC's in just 5 minutes? View the Car PC 101 video
-Help me kill my car PC
-Watch live video streams from my mobile PC? Check it out here.
-Where is the iBug?
Bugbyte is offline   Reply With Quote
Advertisement
 
Advertisement
Sponsored links

Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Touch Screen Based Gesture Interface? Lazyflip Software & Software Development 13 01-25-2006 03:28 PM
Dim LCD based on ambient light neon_eddy LCD/Display 3 12-01-2005 08:02 AM
Request: Time based gamma control. TRONiC Centrafuse 2 09-20-2005 08:16 PM
FS: DWW-7VGA 7" Touch Screen VGA LCD * Based on the Xenarc/Gain 7" VGA LCD faichiu Classified Archive 6 10-20-2004 03:30 AM
Problems with screen backlight and allen controller setup MikeHunt79 LCD/Display 13 07-02-2002 11:54 AM



All times are GMT -5. The time now is 12:34 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.2
Copyright © 1999 - 2008 Mp3Car.com Inc.Ad Management by RedTyger
Message Board Statistics