Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions Click2Minimize/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ struct Click2MinimizeApp: App {
Divider()

// New button to open System Preferences for Accessibility
Button(action: appDelegate.openAccessibilityPreferences, label: { Text("Accessibility Preferences") })
Button(action: { appDelegate.openSystemPreferences(pane: "Accessibility") }, label: { Text("Accessibility Preferences") })

// New button to open System Preferences for Automation
Button(action: appDelegate.openAutomationPreferences, label: { Text("Automation Preferences") })
Button(action: { appDelegate.openSystemPreferences(pane: "Automation") }, label: { Text("Automation Preferences") })
Divider()

Button(action: appDelegate.quitApp, label: { Text("Quit") })
Expand Down Expand Up @@ -359,7 +359,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {

let response = alert.runModal()
if response == .alertFirstButtonReturn {
openAccessibilityPreferences()
openSystemPreferences(pane: "Accessibility")
// Quit the application as it won't work without permission
// Delay termination by 1 second
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
Expand All @@ -368,13 +368,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}

func openAccessibilityPreferences() {
let url = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility")!
NSWorkspace.shared.open(url)
}

func openAutomationPreferences() {
let url = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Automation")!
func openSystemPreferences(pane: String) {
let url = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_\(pane)")!
NSWorkspace.shared.open(url)
}

Expand Down