Created
February 13, 2026 12:10
-
-
Save td0m/1e2739a7c930163d46466a5d6003b9e6 to your computer and use it in GitHub Desktop.
mac toggle grayscale
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| // Load the private framework | |
| guard let handle = dlopen("/System/Library/PrivateFrameworks/UniversalAccess.framework/UniversalAccess", RTLD_NOW) else { | |
| fatalError("Unable to load UniversalAccess framework") | |
| } | |
| defer { | |
| dlclose(handle) | |
| } | |
| // Define function signatures | |
| typealias UAGrayscaleIsEnabledFunc = @convention(c) () -> Bool | |
| typealias UAGrayscaleSetEnabledFunc = @convention(c) (Bool) -> Void | |
| // Load symbols | |
| guard | |
| let isEnabledSym = dlsym(handle, "UAGrayscaleIsEnabled"), | |
| let setEnabledSym = dlsym(handle, "UAGrayscaleSetEnabled") | |
| else { | |
| fatalError("Unable to load symbols") | |
| } | |
| // Cast to callable functions | |
| let UAGrayscaleIsEnabled = unsafeBitCast(isEnabledSym, to: UAGrayscaleIsEnabledFunc.self) | |
| let UAGrayscaleSetEnabled = unsafeBitCast(setEnabledSym, to: UAGrayscaleSetEnabledFunc.self) | |
| // Toggle grayscale | |
| let current = UAGrayscaleIsEnabled() | |
| UAGrayscaleSetEnabled(!current) | |
| print("Grayscale now: \(!current)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment