Skip to content

Instantly share code, notes, and snippets.

@td0m
Created February 13, 2026 12:10
Show Gist options
  • Select an option

  • Save td0m/1e2739a7c930163d46466a5d6003b9e6 to your computer and use it in GitHub Desktop.

Select an option

Save td0m/1e2739a7c930163d46466a5d6003b9e6 to your computer and use it in GitHub Desktop.
mac toggle grayscale
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