Skip to content

Commit

Permalink
Update main.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Feb 23, 2024
1 parent d6095cf commit 2e778e3
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions Sources/ActiveWinCLI/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ func getWindowInformation(window: [String: Any], windowOwnerPID: pid_t) -> [Stri
"memoryUsage": window[kCGWindowMemoryUsage as String] as? Int ?? 0
]

// Run the AppleScript to get the URL if active window is a compatible browser and accessibility permissions are enabled.
if !disableAccessibilityPermission {
if let bundleIdentifier = app.bundleIdentifier,
let script = getActiveBrowserTabURLAppleScriptCommand(bundleIdentifier),
let url = runAppleScript(source: script)
{
output["url"] = url
}
// Run the AppleScript to get the URL if the active window is a compatible browser and accessibility permissions are enabled.
if
!disableAccessibilityPermission,
let bundleIdentifier = app.bundleIdentifier,
let script = getActiveBrowserTabURLAppleScriptCommand(bundleIdentifier),
let url = runAppleScript(source: script)
{
output["url"] = url
}

return output
Expand All @@ -89,13 +89,19 @@ let disableScreenRecordingPermission = CommandLine.arguments.contains("--no-scre
let enableOpenWindowsList = CommandLine.arguments.contains("--open-windows-list")

// Show accessibility permission prompt if needed. Required to get the URL of the active tab in browsers.
if !disableAccessibilityPermission && !AXIsProcessTrustedWithOptions(["AXTrustedCheckOptionPrompt": true] as CFDictionary) {
if
!disableAccessibilityPermission,
!AXIsProcessTrustedWithOptions(["AXTrustedCheckOptionPrompt": true] as CFDictionary)
{
print("active-win requires the accessibility permission in “System Settings › Privacy & Security › Accessibility”.")
exit(1)
}

// Show screen recording permission prompt if needed. Required to get the complete window title.
if !disableScreenRecordingPermission && !hasScreenRecordingPermission() {
if
!disableScreenRecordingPermission,
!hasScreenRecordingPermission()
{
print("active-win requires the screen recording permission in “System Settings › Privacy & Security › Screen Recording”.")
exit(1)
}
Expand Down

0 comments on commit 2e778e3

Please sign in to comment.