Skip to content

Instantly share code, notes, and snippets.

@thewh1teagle
Created July 23, 2024 16:02
Show Gist options
  • Select an option

  • Save thewh1teagle/8b8b953e453761358956a8f090ab228e to your computer and use it in GitHub Desktop.

Select an option

Save thewh1teagle/8b8b953e453761358956a8f090ab228e to your computer and use it in GitHub Desktop.
request screen capture permission with swift
import ScreenCaptureKit
import Cocoa
let accessEnabled = CGPreflightScreenCaptureAccess()
func openSystemPreferences() {
let url = "x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture"
if let nsUrl = URL(string: url) {
NSWorkspace.shared.open(nsUrl)
}
}
if accessEnabled {
print("Permissions are enabled")
} else {
openSystemPreferences()
CGRequestScreenCaptureAccess()
// CGRequestScreenCaptureAccess()
print("Permissions are not enabled")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment