Skip to content

Commit ed7b9ea

Browse files
committed
Adding back old macos method
1 parent 5002b32 commit ed7b9ea

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

aw_watcher_window/lib.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import sys
22
from typing import Optional
33

4-
54
def get_current_window_linux() -> Optional[dict]:
65
from . import xlib
76
window = xlib.get_current_window()
@@ -16,10 +15,16 @@ def get_current_window_linux() -> Optional[dict]:
1615
return {"app": cls, "title": name}
1716

1817

19-
def get_current_window_macos() -> Optional[dict]:
18+
def get_current_window_macos(strategy) -> Optional[dict]:
2019
# TODO should we use unknown when the title is blank like the other platforms?
21-
from . import macos
22-
return macos.getInfo()
20+
21+
# `jxa` is the default & preferred strategy. It includes the url + incognito status
22+
if strategy == 'jxa':
23+
from . import macos
24+
return macos.getInfo()
25+
else:
26+
from . import macos_applescript
27+
return macos_applescript.getInfo()
2328

2429

2530
def get_current_window_windows() -> Optional[dict]:
@@ -36,11 +41,11 @@ def get_current_window_windows() -> Optional[dict]:
3641
return {"app": app, "title": title}
3742

3843

39-
def get_current_window() -> Optional[dict]:
44+
def get_current_window(macos_strategy) -> Optional[dict]:
4045
if sys.platform.startswith("linux"):
4146
return get_current_window_linux()
4247
elif sys.platform == "darwin":
43-
return get_current_window_macos()
48+
return get_current_window_macos(macos_strategy)
4449
elif sys.platform in ["win32", "cygwin"]:
4550
return get_current_window_windows()
4651
else:
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import subprocess
2+
from subprocess import PIPE
3+
import os
4+
5+
6+
def getInfo() -> str:
7+
cmd = ["osascript", os.path.join(os.path.dirname(os.path.realpath(__file__)), "printAppTitle.scpt")]
8+
p = subprocess.run(cmd, stdout=PIPE)
9+
return str(p.stdout, "utf8").strip()
10+
11+
12+
def getApp(info: str) -> str:
13+
return info.split('","')[0][1:]
14+
15+
16+
def getTitle(info: str) -> str:
17+
return info.split('","')[1][:-1]
3.12 KB
Binary file not shown.

0 commit comments

Comments
 (0)