screen_brightness_control icon indicating copy to clipboard operation
screen_brightness_control copied to clipboard

[FR] MAC is not yet supported

Open arsikurin opened this issue 2 years ago • 8 comments

When do you plan to add support for Macs?

arsikurin avatar Apr 13 '22 07:04 arsikurin

Unfortunately, I currently have no plans to support Macs.

The main problem is that I do not own or have access to a Mac, which means I can't test any code on the platform. I have no idea how brightness works on Macs, whether iMac screens are adjustable like Macbooks or if there's an exposed API like wmi.

If I ever manage to gain access to a Mac then adding support to the library is high on the to-do list.

Crozzers avatar Apr 13 '22 14:04 Crozzers

to increase(num)
	tell application "System Events"
		repeat num as integer times
			delay 0.05
			key code 144
		end repeat
	end tell
end increase

to decrease(num)
	tell application "System Events"
		repeat num as integer times
			delay 0.05
			key code 145
		end repeat
	end tell
end decrease

on run argv
	if ((count of argv) > 1) then
		increase(item 2 of argv)
	else
		decrease(item 1 of argv)
	end if
end run

here's AppleScript to achieve changing brightness on Macs. Frankly, it's my first time writing AppleScript, so code might not be as efficient.

To use it you should execute this file in terminal and pass number of segments to increase/decrease

arsikurin avatar Apr 13 '22 20:04 arsikurin

That is certainly one way to do it, and it's certainly similar to the Linux side, which also calls commands from the terminal. However, this still leaves a few unanswered questions:

  1. What happens if Apple moves the brightness keys?
    • Do the key codes change?
    • Have they done this before? (after a google images search of macbook keyboards I don't think so)
  2. What about on devices using a USB keyboard without dedicated brightness keys?
  3. Can this be adapted to work on external displays?
    • The Apple keyboard shortcuts guide seems to suggest it can
    • Control-Brightness Up or Control-Brightness Down: Change the brightness of your external display, if supported by your display.

    • However there is no mention of what displays are supported
  4. Finally, and quite importantly, how does one get the current brightness?

These are all things that are probably simple enough to find out and deal with but that is something I cannot really do without a Mac to hand

Crozzers avatar Apr 13 '22 22:04 Crozzers

Upon researching this a bit further, I have found a few interesting projects on this topic.

  1. MonitorControl This one can control external displays over DDC/CI but it's written in Swift so some of the APIs might not be accessible via Python

  2. ddcctl by kfix Same sorta thing but written (at least partly) in C, so it might be easier to interface with.

I'm hesitant to include any compiled languages in the project, however, as it would mean I would have to find a MAC to re-compile the project on for every release.

  1. brightness by Alex DeLorenzo This one is the most interesting in my opinion. It's a Python project that manages to use Apple's CoreDisplay API, the details of which are documented in the accompanying blog post. This seems like the closest MacOS has to the Windows wmi API.

This is all interesting stuff that demonstrates that Mac support is at least feasible.

EDIT: See also ddc over i2c on macOS

Crozzers avatar Apr 13 '22 22:04 Crozzers

@arsikurin Do you know about PyObjC? I have 2 realisation for adjust of brightness, for determine display and for all.

Alexandro1112 avatar May 27 '23 19:05 Alexandro1112

I used this in my project:

brightness by Alex DeLorenzo This one is the most interesting in my opinion. It's a Python project that manages to use Apple's CoreDisplay API, the details of which are documented in the accompanying blog post. This seems like the closest MacOS has to the Windows wmi API.

https://github.com/alexdelorenzo/brightness

arsikurin avatar May 27 '23 19:05 arsikurin

Same implementation with IOKit. But someone has a macOS print error that is associated with access to the display.I prefer to use Quartz.IKMonitorBrightnessController to adjust the brightness.

Alexandro1112 avatar May 27 '23 20:05 Alexandro1112

I even not know why mac return error code when I use function, contain in IOKit. For example IODisplaySetFloatParameter does not adjust set brightness, but return error code -536870201. I have found out that, error mean absence access to main/external displays.

Alexandro1112 avatar May 27 '23 20:05 Alexandro1112