Michael Pasqualone
Michael Pasqualone

Reputation: 2037

Programmatically turn off an individual monitor

Is there an API or way to programmatically turn off an individual, external monitor via Objective-C on a Mac?

I'm looking to write a small menubar application that can control a secondary display (without a physical power button), but still keep the primary monitor in use.

Hunting around the API documentation, I can't seem to find anything, other then reading states. So hoping someone else might have an idea.

Upvotes: 8

Views: 2571

Answers (2)

Hailei
Hailei

Reputation: 42163

It seems to be possible to sleep display so by I/O Kit:

But I am not sure whether it can control single monitors.

Upvotes: 2

user244343
user244343

Reputation:

You can't "programmatically turn off an individual monitor", it's not physically possible. The most you can do is tell the OS to not use the monitor, but I don't think you can change system-wide settings like that, especially not at the level you're working on (Obj-C).

Looking at the Core Graphics API mentioned in @Halley's comment, try starting with the CGBeginDisplayConfiguration method and see if you can set a display configuration to your liking.

EDIT: Alternatively, you could also use CGDisplayCapture(displayID), which by default fills the captured display with black. You can then call CGDisplayRelease(displayID) when you want to turn it back on.

Upvotes: 1

Related Questions