|
1 | 1 | import subprocess |
| 2 | +import re |
2 | 3 |
|
3 | 4 | from talon import Context, Module, actions, settings |
4 | 5 |
|
@@ -246,7 +247,28 @@ def language(): |
246 | 247 |
|
247 | 248 |
|
248 | 249 | def obsidian_run_cli_command(command_id: str): |
249 | | - subprocess.run(["obsidian", "command", f"id={command_id}"], timeout=1.0) |
| 250 | + try: |
| 251 | + subprocess.check_output( |
| 252 | + ["obsidian", "command", f"id={command_id}"], timeout=1.0 |
| 253 | + ) |
| 254 | + except OSError as e: |
| 255 | + print(f"Error running obsidian command via cli: {e}") |
| 256 | + print("Obsidian might not be on PATH?") |
| 257 | + except subprocess.CalledProcessError as e: |
| 258 | + # Note: As of at least obsidian version 1.12, the CLI never emits a failure exit code, so none of these will trigger currently, but a future update to obsidian might fix that. |
| 259 | + print(f"Error running obsidian command via cli: {e.output}") |
| 260 | + if "Command line interface is not enabled" in e.output: |
| 261 | + print( |
| 262 | + "Talon settings say to use the obsidian CLI for obsidian commands, but CLI interface control is disabled in obsidian settings." |
| 263 | + ) |
| 264 | + print("Please turn it on in Settings > General >Advanced") |
| 265 | + elif re.match('Command "[^"]*"not found', e.output): |
| 266 | + print( |
| 267 | + f"Command '{command_id}' does not seem to be a valid obsidian command" |
| 268 | + ) |
| 269 | + |
| 270 | + print(f"Falling back to palette command for {command_id}") |
| 271 | + obsidian_palette_command(command_id) |
250 | 272 |
|
251 | 273 |
|
252 | 274 | def command_uri_or_client_fallback(command_id: str): |
|
0 commit comments