@@ -18,29 +18,31 @@ def find_browser(name):
18
18
:param name: The name of the browser.
19
19
:return: AXUIElement or None.
20
20
"""
21
-
22
- ws = NSWorkspace .sharedWorkspace ()
23
- regular_predicate = NSPredicate .predicateWithFormat_ (
24
- f"activationPolicy == { NSApplicationActivationPolicyRegular } "
25
- )
26
- running_apps = ws .runningApplications ().filteredArrayUsingPredicate_ (
27
- regular_predicate
28
- )
29
- name_predicate = NSPredicate .predicateWithFormat_ (
30
- f"localizedName contains[c] '{ name } '"
31
- )
32
- filtered_apps = running_apps .filteredArrayUsingPredicate_ (name_predicate )
33
- if filtered_apps .count () == 0 :
34
- return None
35
- app = filtered_apps [0 ]
36
- pid = app .processIdentifier ()
37
- if pid == - 1 :
38
- return None
39
-
40
- # If accessibility is not enabled, the following API call will error.
21
+ print (f"Can I see these print statements?????????????????????????????" , file = sys .stderr , flush = True )
41
22
try :
42
- return AXUIElementCreateApplication (pid )
43
- except Exception :
23
+ ws = NSWorkspace .sharedWorkspace ()
24
+ regular_predicate = NSPredicate .predicateWithFormat_ (
25
+ f"activationPolicy == { NSApplicationActivationPolicyRegular } "
26
+ )
27
+ running_apps = ws .runningApplications ().filteredArrayUsingPredicate_ (
28
+ regular_predicate
29
+ )
30
+ name_predicate = NSPredicate .predicateWithFormat_ (
31
+ f"localizedName contains[c] '{ name } '"
32
+ )
33
+ filtered_apps = running_apps .filteredArrayUsingPredicate_ (name_predicate )
34
+ if filtered_apps .count () == 0 :
35
+ return None
36
+ app = filtered_apps [0 ]
37
+ pid = app .processIdentifier ()
38
+ if pid == - 1 :
39
+ return None
40
+
41
+ ax_element = AXUIElementCreateApplication (pid )
42
+ return ax_element
43
+
44
+ except Exception as e :
45
+ print (f"Error finding browser: { e } " , file = sys .stderr , flush = True )
44
46
return None
45
47
46
48
0 commit comments