From 39a3cb968c5c19b6ae07dca76ff8c797a8938ccc Mon Sep 17 00:00:00 2001 From: kentbetita Date: Wed, 21 Feb 2024 06:23:39 +0800 Subject: [PATCH 1/7] =?UTF-8?q?feat:=20add=20`accessibilityPermission`=20o?= =?UTF-8?q?ption=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/ActiveWinCLI/main.swift | 3 ++- index.d.ts | 9 +++++++++ index.test-d.ts | 5 ++++- lib/macos.js | 4 ++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Sources/ActiveWinCLI/main.swift b/Sources/ActiveWinCLI/main.swift index fa260f0..3e8e959 100644 --- a/Sources/ActiveWinCLI/main.swift +++ b/Sources/ActiveWinCLI/main.swift @@ -83,11 +83,12 @@ func getWindowInformation(window: [String: Any], windowOwnerPID: pid_t) -> [Stri return output } +let disableAccessibilityPermission = CommandLine.arguments.contains("--no-accessibility-permission") let disableScreenRecordingPermission = CommandLine.arguments.contains("--no-screen-recording-permission") let enableOpenWindowsList = CommandLine.arguments.contains("--open-windows-list") // Show accessibility permission prompt if needed. Required to get the complete window title. -if !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) } diff --git a/index.d.ts b/index.d.ts index fd4fd55..8305ddc 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,5 +1,14 @@ declare namespace activeWindow { interface Options { + /** + Enable the accessibility permission check. _(macOS)_ + + Setting this to `false` will prevent the accessibility permission prompt on macOS versions 10.15 and newer. + + @default true + */ + readonly accessibilityPermission: boolean; + /** Enable the screen recording permission check. _(macOS)_ diff --git a/index.test-d.ts b/index.test-d.ts index c83e2d3..10a9993 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -4,7 +4,10 @@ import {Result, LinuxResult, MacOSResult, WindowsResult, BaseOwner} from './inde expectType>(activeWindow()); -const result = activeWindow.sync({screenRecordingPermission: false}); +const result = activeWindow.sync({ + screenRecordingPermission: false, + accessibilityPermission: false +}); expectType(result); diff --git a/lib/macos.js b/lib/macos.js index 4b21bce..9a5bb1a 100644 --- a/lib/macos.js +++ b/lib/macos.js @@ -21,6 +21,10 @@ const getArguments = options => { } const args = []; + if (options.accessibilityPermission === false) { + args.push('--no-accessibility-permission'); + } + if (options.screenRecordingPermission === false) { args.push('--no-screen-recording-permission'); } From d91b737529dc23b1c6fde7d0cfddb79d4557414b Mon Sep 17 00:00:00 2001 From: kentbetita Date: Wed, 21 Feb 2024 06:24:03 +0800 Subject: [PATCH 2/7] =?UTF-8?q?doc:=20add=20`accessibilityPermission`=20to?= =?UTF-8?q?=20readme=20=F0=9F=93=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/readme.md b/readme.md index 5b071d0..4a96ba3 100644 --- a/readme.md +++ b/readme.md @@ -50,6 +50,13 @@ Get metadata about the active window. Type: `object` +##### accessibilityPermission **(macOS only)** + +Type: `boolean`\ +Default: `true` + +Enable the accessibility permission check. Setting this to `false` will prevent the accessibility permission prompt on macOS versions 10.15 and newer. + ##### screenRecordingPermission **(macOS only)** Type: `boolean`\ From 8accefff6abeb7afda487792f96699b4617dcd59 Mon Sep 17 00:00:00 2001 From: kentbetita Date: Wed, 21 Feb 2024 06:43:45 +0800 Subject: [PATCH 3/7] =?UTF-8?q?fix:=20remove=20trailing=20space=20?= =?UTF-8?q?=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.test-d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.test-d.ts b/index.test-d.ts index 10a9993..4065154 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -5,7 +5,7 @@ import {Result, LinuxResult, MacOSResult, WindowsResult, BaseOwner} from './inde expectType>(activeWindow()); const result = activeWindow.sync({ - screenRecordingPermission: false, + screenRecordingPermission: false, accessibilityPermission: false }); From 511504d2ea02d2d810484622caff2ab4e043819a Mon Sep 17 00:00:00 2001 From: kentbetita Date: Thu, 22 Feb 2024 16:49:21 +0800 Subject: [PATCH 4/7] =?UTF-8?q?doc:=20update=20description=20=F0=9F=93=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.d.ts | 2 +- readme.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 8305ddc..f2f360a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -3,7 +3,7 @@ declare namespace activeWindow { /** Enable the accessibility permission check. _(macOS)_ - Setting this to `false` will prevent the accessibility permission prompt on macOS versions 10.15 and newer. + Setting this to `false` will prevent the accessibility permission prompt on macOS versions 10.15 and newer. The `url` property won't be retrieved. @default true */ diff --git a/readme.md b/readme.md index 4a96ba3..d6da80a 100644 --- a/readme.md +++ b/readme.md @@ -55,7 +55,7 @@ Type: `object` Type: `boolean`\ Default: `true` -Enable the accessibility permission check. Setting this to `false` will prevent the accessibility permission prompt on macOS versions 10.15 and newer. +Enable the accessibility permission check. Setting this to `false` will prevent the accessibility permission prompt on macOS versions 10.15 and newer. The `url` property won't be retrieved. ##### screenRecordingPermission **(macOS only)** From 351892e0e71742193a335fb909c637a22f05d7c7 Mon Sep 17 00:00:00 2001 From: kentbetita Date: Thu, 22 Feb 2024 17:55:37 +0800 Subject: [PATCH 5/7] =?UTF-8?q?chore:=20omit=20URL=20from=20output=20?= =?UTF-8?q?=F0=9F=94=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/ActiveWinCLI/main.swift | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Sources/ActiveWinCLI/main.swift b/Sources/ActiveWinCLI/main.swift index 3e8e959..9a72290 100644 --- a/Sources/ActiveWinCLI/main.swift +++ b/Sources/ActiveWinCLI/main.swift @@ -71,13 +71,14 @@ func getWindowInformation(window: [String: Any], windowOwnerPID: pid_t) -> [Stri "memoryUsage": window[kCGWindowMemoryUsage as String] as? Int ?? 0 ] - // Only run the AppleScript if active window is a compatible browser. - 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 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 + } } return output From d6095cfbfa749b660777731c5032b27ba8eb16c5 Mon Sep 17 00:00:00 2001 From: kentbetita Date: Thu, 22 Feb 2024 17:58:58 +0800 Subject: [PATCH 6/7] =?UTF-8?q?doc:=20update=20comment=20=F0=9F=93=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/ActiveWinCLI/main.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/ActiveWinCLI/main.swift b/Sources/ActiveWinCLI/main.swift index 9a72290..33104e7 100644 --- a/Sources/ActiveWinCLI/main.swift +++ b/Sources/ActiveWinCLI/main.swift @@ -88,7 +88,7 @@ let disableAccessibilityPermission = CommandLine.arguments.contains("--no-access let disableScreenRecordingPermission = CommandLine.arguments.contains("--no-screen-recording-permission") let enableOpenWindowsList = CommandLine.arguments.contains("--open-windows-list") -// Show accessibility permission prompt if needed. Required to get the complete window title. +// Show accessibility permission prompt if needed. Required to get the URL of the active tab in browsers. if !disableAccessibilityPermission && !AXIsProcessTrustedWithOptions(["AXTrustedCheckOptionPrompt": true] as CFDictionary) { print("active-win requires the accessibility permission in “System Settings › Privacy & Security › Accessibility”.") exit(1) From 2e778e3c67f17fbfb5a5f43f51dfd91ce7e61db5 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 23 Feb 2024 10:14:37 +0700 Subject: [PATCH 7/7] Update main.swift --- Sources/ActiveWinCLI/main.swift | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Sources/ActiveWinCLI/main.swift b/Sources/ActiveWinCLI/main.swift index 33104e7..59b10d4 100644 --- a/Sources/ActiveWinCLI/main.swift +++ b/Sources/ActiveWinCLI/main.swift @@ -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 @@ -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) }