有沒有辦法在Objective-C中調整Mac的顯示亮度?我有敏感的眼睛,有時候顯示器看起來可能會變暗。與Jeff's blog post關於極客和黑暗相結合,它可以變得非常討厭。調整Mac顯示屏亮度Objective-C?
我認爲這是有原因的,如果顯示器可以設置爲數字值,它可以設置爲低於常規屏幕亮度。我已經Google了谷歌,但所有的事情都是關於iPhone的。有沒有辦法爲Mac做到這一點?
有沒有辦法在Objective-C中調整Mac的顯示亮度?我有敏感的眼睛,有時候顯示器看起來可能會變暗。與Jeff's blog post關於極客和黑暗相結合,它可以變得非常討厭。調整Mac顯示屏亮度Objective-C?
我認爲這是有原因的,如果顯示器可以設置爲數字值,它可以設置爲低於常規屏幕亮度。我已經Google了谷歌,但所有的事情都是關於iPhone的。有沒有辦法爲Mac做到這一點?
只是搜索一下,發現這:) :)
這是代碼如何獲得亮度。
// almost completely from: http://mattdanger.net/2008/12/adjust-mac-os-x-display-brightness-from-the-terminal/
- (float) get_brightness {
CGDirectDisplayID display[kMaxDisplays];
CGDisplayCount numDisplays;
CGDisplayErr err;
err = CGGetActiveDisplayList(kMaxDisplays, display, &numDisplays);
if (err != CGDisplayNoErr)
printf("cannot get list of displays (error %d)\n",err);
for (CGDisplayCount i = 0; i < numDisplays; ++i) {
CGDirectDisplayID dspy = display[i];
CFDictionaryRef originalMode = CGDisplayCurrentMode(dspy);
if (originalMode == NULL)
continue;
io_service_t service = CGDisplayIOServicePort(dspy);
float brightness;
err= IODisplayGetFloatParameter(service, kNilOptions, kDisplayBrightness,
&brightness);
if (err != kIOReturnSuccess) {
fprintf(stderr,
"failed to get brightness of display 0x%x (error %d)",
(unsigned int)dspy, err);
continue;
}
return brightness;
}
return -1.0;//couldn't get brightness for any display
}
如何設置亮度。
// almost completely from: http://mattdanger.net/2008/12/adjust-mac-os-x-display-brightness-from-the-terminal/
- (void) set_brightness:(float) new_brightness {
CGDirectDisplayID display[kMaxDisplays];
CGDisplayCount numDisplays;
CGDisplayErr err;
err = CGGetActiveDisplayList(kMaxDisplays, display, &numDisplays);
if (err != CGDisplayNoErr)
printf("cannot get list of displays (error %d)\n",err);
for (CGDisplayCount i = 0; i < numDisplays; ++i) {
CGDirectDisplayID dspy = display[i];
CFDictionaryRef originalMode = CGDisplayCurrentMode(dspy);
if (originalMode == NULL)
continue;
io_service_t service = CGDisplayIOServicePort(dspy);
float brightness;
err= IODisplayGetFloatParameter(service, kNilOptions, kDisplayBrightness,
&brightness);
if (err != kIOReturnSuccess) {
fprintf(stderr,
"failed to get brightness of display 0x%x (error %d)",
(unsigned int)dspy, err);
continue;
}
err = IODisplaySetFloatParameter(service, kNilOptions, kDisplayBrightness,
new_brightness);
if (err != kIOReturnSuccess) {
fprintf(stderr,
"Failed to set brightness of display 0x%x (error %d)",
(unsigned int)dspy, err);
continue;
}
if(brightness > 0.0){
}else{
}
}
}
我在這裏找到了 - http://www.alecjacobson.com/weblog/?tag=brightness。
這是從相同的答案:http://stackoverflow.com/questions/3239749/programmatically-change-mac-display-brightness – 2012-03-15 14:29:20
你明白了。一個cocmmand行示例可以在這裏找到:[Matt Danger](http://mattdanger.net/2008/12/adjust-mac-os-x-display-brightness-from-the-terminal/) – 2012-03-15 14:30:06
它告訴我'未能設置顯示器的亮度0x506ef80(錯誤-536870201)' – CoffeeRain 2012-03-15 14:34:13
請原諒我的無知,爲什麼您的程序會在通過系統偏好設置輕鬆完成時執行此操作? – 2012-03-15 14:24:27
http://stackoverflow.com/questions/3239749/programmatically-change-mac-display-brightness – 2012-03-15 14:25:59
http://stackoverflow.com/questions/818829/how-to-dim-os-x-desktop-using-cocoa -core-animation – 2012-03-15 14:26:38