Welcome to the MP3Car.com forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. Registering will also remove advertisements. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact contact us.
|
07-18-2006, 09:29 AM
|
#1
|
|
Low Bitrate
Join Date: Apr 2006
Location: Maryland
Vehicle: 2000 VW Jetta
Posts: 82
|
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! 
|
|
|
07-18-2006, 10:31 AM
|
#2
|
|
AMP Creator
Join Date: Jun 2006
Posts: 442
|
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.
|
|
|
07-18-2006, 11:59 AM
|
#3
|
|
Low Bitrate
Join Date: Apr 2006
Location: Maryland
Vehicle: 2000 VW Jetta
Posts: 82
|
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).
|
|
|
07-19-2006, 01:49 PM
|
#4
|
|
QCar Creator
Join Date: Jul 2005
Location: Netherlands
Vehicle: 1993 Tatra 613-4Mi Long
Posts: 540
|
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();
}
|
|
|
07-19-2006, 04:53 PM
|
#5
|
|
Maximum Bitrate
Join Date: Dec 2005
Location: Langley AFB
Vehicle: 2006 Saturn Ion2
Posts: 549
|
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!
|
|
|
07-19-2006, 09:05 PM
|
#6
|
|
Admin
Join Date: Sep 2004
Location: Corning, NY
Vehicle: 2001 VW Beetle
Posts: 4,413
|
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
|
|
|
07-20-2006, 09:38 PM
|
#7
|
|
Low Bitrate
Join Date: Apr 2006
Location: Maryland
Vehicle: 2000 VW Jetta
Posts: 82
|
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!
|
|
|
07-21-2006, 03:50 PM
|
#8
|
|
Admin
Join Date: Sep 2004
Location: Corning, NY
Vehicle: 2001 VW Beetle
Posts: 4,413
|
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
Last edited by Bugbyte : 07-21-2006 at 04:00 PM.
|
|
|
07-21-2006, 03:58 PM
|
#9
|
|
FLAC
Join Date: Apr 2005
Location: Boston, MA
Vehicle: 2002 Chrysler Sebring Coupe LXI
Posts: 1,747
|
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.
|
|
|
07-22-2006, 11:58 AM
|
#10
|
|
Low Bitrate
Join Date: Apr 2006
Location: Maryland
Vehicle: 2000 VW Jetta
Posts: 82
|
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.
|
|
|
07-22-2006, 12:18 PM
|
#11
|
|
Low Bitrate
Join Date: Apr 2006
Location: Maryland
Vehicle: 2000 VW Jetta
Posts: 82
|
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.
|
|
|
03-17-2007, 02:35 AM
|
#12
|
|
Low Bitrate
Join Date: Apr 2006
Location: Maryland
Vehicle: 2000 VW Jetta
Posts: 82
|
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 02:41 AM.
Reason: clarifying a bit
|
|
|
03-17-2007, 02:23 PM
|
#13
|
|
Admin
Join Date: Sep 2004
Location: Corning, NY
Vehicle: 2001 VW Beetle
Posts: 4,413
|
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.
|
|
|
03-17-2007, 03:17 PM
|
#14
|
|
QCar Creator
Join Date: Jul 2005
Location: Netherlands
Vehicle: 1993 Tatra 613-4Mi Long
Posts: 540
|
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.
|
|
|
03-17-2007, 03:22 PM
|
#15
|
|
Admin
Join Date: Sep 2004
Location: Corning, NY
Vehicle: 2001 VW Beetle
Posts: 4,413
|
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.
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 06:02 AM.
|
|