Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] MAC is not yet supported #16

Open
arsikurin opened this issue Apr 13, 2022 · 8 comments
Open

[FR] MAC is not yet supported #16

arsikurin opened this issue Apr 13, 2022 · 8 comments
Labels
question Further information is requested

Comments

@arsikurin
Copy link

When do you plan to add support for Macs?

@Crozzers
Copy link
Owner

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 Crozzers added the question Further information is requested label Apr 13, 2022
@arsikurin
Copy link
Author

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

@Crozzers
Copy link
Owner

Crozzers commented Apr 13, 2022

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
Copy link
Owner

Crozzers commented Apr 13, 2022

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

@Alexandro1112
Copy link

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

@arsikurin
Copy link
Author

arsikurin commented May 27, 2023

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

@Alexandro1112
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants