Skip to content

Commit 0e5c115

Browse files
committed
Use new jxa implementation in macos python branch
1 parent dd4bd96 commit 0e5c115

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

aw_watcher_window/lib.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@ def get_current_window_linux() -> Optional[dict]:
1717

1818

1919
def get_current_window_macos() -> Optional[dict]:
20+
# TODO should we use unknown when the title is blank like the other platforms?
2021
from . import macos
21-
info = macos.getInfo()
22-
app = macos.getApp(info)
23-
title = macos.getTitle(info)
24-
25-
return {"title": title, "appname": app}
22+
return macos.getInfo()
2623

2724

2825
def get_current_window_windows() -> Optional[dict]:

aw_watcher_window/macos.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
import subprocess
2-
from subprocess import PIPE
32
import os
3+
import json
4+
import logging
45

6+
logger = logging.getLogger(__name__)
57

68
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]
18-
9+
cmd = [os.path.join(os.path.dirname(os.path.realpath(__file__)), "printAppStatus.jxa")]
10+
p = subprocess.run(cmd, stdout=subprocess.PIPE)
11+
result = str(p.stdout, "utf8").strip()
12+
13+
try:
14+
return json.loads(result)
15+
except JSONDecodeError as e:
16+
logger.warn("invalid JSON encountered {result}")
17+
return {}
1918

2019
def background_ensure_permissions() -> None:
2120
from multiprocessing import Process

0 commit comments

Comments
 (0)