Skip to content

Instantly share code, notes, and snippets.

@thewh1teagle
Created May 7, 2024 13:22
Show Gist options
  • Save thewh1teagle/ba62761d1fe4970128dfa21b51afa04d to your computer and use it in GitHub Desktop.
Save thewh1teagle/ba62761d1fe4970128dfa21b51afa04d to your computer and use it in GitHub Desktop.

Accessibility control permission checking on macOS

image

use accessibility_sys::AXIsProcessTrustedWithOptions;
use core_foundation_sys::base::{CFRelease, TCFTypeRef};
use core_foundation_sys::dictionary::{CFDictionaryAddValue, CFDictionaryCreateMutable};
use core_foundation_sys::number::kCFBooleanTrue;
use std::ffi::CString;
use std::ptr;
fn main() {
let mut is_allowed = false;
unsafe {
let options =
CFDictionaryCreateMutable(ptr::null_mut(), 1, std::ptr::null(), std::ptr::null());
let key = CString::new("AXTrustedCheckOptionPrompt").unwrap();
let value = kCFBooleanTrue;
CFDictionaryAddValue(options, key.as_ptr().as_void_ptr(), value.as_void_ptr());
is_allowed = AXIsProcessTrustedWithOptions(options);
CFRelease(options as *const _);
}
println!("Accessibility permission enabled: {}", is_allowed);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment