Yes, it can be done by compiling against the private MonitorPanel.framework
which is what System Settings uses to change resolutions and presets.
Here is a simple Swift file that can list and change presets along with the required headers to compile it. I also provide a compiled binary and Apple Shortcuts support in lunar.fyi for convenience.
And here's some sample code to list displays with their active preset, then activating the "Design & Print (P3-D50)" preset for the first display.
presets.swift
guard let mgr = MPDisplayMgr(), let display = mgr.displays.first(where: \.hasPresets) else {
exit(1)
}
print("\(display.displayName!): \"\(display.activePreset!.presetName!)\"")
if let preset = display.presets.first(where: { $0.presetName == "Design & Print (P3-D50)" }) {
print("Activating preset \"Design & Print (P3-D50)\" for \(display.displayName!)")
display.setActivePreset(preset)
}
Bridging-Header.h
#import <MonitorPanel/MPDisplayPreset.h>
#import <MonitorPanel/MPDisplay.h>
#import <MonitorPanel/MPDisplayMgr.h>
#import <MonitorPanel/MPDisplayMode.h>
Compiler command:
swiftc -F$PWD/Headers \
-F/System/Library/PrivateFrameworks \
-framework MonitorPanel \
-import-objc-header Bridging-Header.h \
presets.swift -o presets
./presets