Conditions | 7 |
Total Lines | 29 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | from pathlib import Path |
||
7 | def call( |
||
8 | path: Path, |
||
9 | signature: str, |
||
10 | replacements: dict | None = None, |
||
11 | *, |
||
12 | show_error: bool = True, |
||
13 | ) -> bool: |
||
14 | functions = path.read_text("utf-8") |
||
15 | |||
16 | if replacements is None: |
||
17 | replacements = {} |
||
18 | for old, new in replacements.items(): |
||
19 | if old != new: |
||
20 | functions = functions.replace(old, new) |
||
21 | log.debug(f"Replaced {old!r} => {new!r}") |
||
22 | |||
23 | log.debug(f"Calling AppleScript: {signature}") |
||
24 | result = applescript.run(functions + "\n\n" + signature) |
||
25 | |||
26 | log.debug(f"AppleScript code: {result.code}") |
||
27 | if result.out: |
||
28 | log.debug(f"AppleScript output: {result.out}") |
||
29 | if result.err: |
||
30 | log.debug(f"AppleScript error: {result.err}") |
||
31 | if show_error: |
||
32 | message = result.err.split("error:")[-1].strip() |
||
33 | log.error(message) |
||
34 | |||
35 | return result.code == 0 and "missing value" not in result.out |
||
36 |