From 8e1d96a18df891d7f4865c7ce90ff53fdd56be2a Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 5 Aug 2023 18:11:28 +0200 Subject: [PATCH] Update for meetup --- plugin/talon_helpers/create_app_context.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/plugin/talon_helpers/create_app_context.py b/plugin/talon_helpers/create_app_context.py index ffd2cdd6c6..8501e661c6 100644 --- a/plugin/talon_helpers/create_app_context.py +++ b/plugin/talon_helpers/create_app_context.py @@ -26,8 +26,11 @@ def talon_create_app_context(): if not app_dir.is_dir(): os.mkdir(app_dir) - create_file(talon_file, talon_context) - create_file(python_file, python_context) + talon_file_created = create_file(talon_file, talon_context) + python_file_created = create_file(python_file, python_context) + + if talon_file_created or python_file_created: + actions.user.file_manager_open_directory(str(app_dir)) def get_python_context(active_app: ui.App, app_name: str) -> str: @@ -43,6 +46,7 @@ def get_python_context(active_app: ui.App, app_name: str) -> str: """ ctx.matches = r""" +os: {os} app: {app_name} """ @@ -63,8 +67,9 @@ def get_talon_context(app_name: str) -> str: def get_platform_filename(app_name: str) -> str: - platform = app.platform if app.platform != "windows" else "win" - return f"{app_name}_{platform}" + if app.platform == "mac": + return f"{app_name}_{app.platform}" + return app_name def get_app_context(active_app: ui.App) -> str: @@ -82,10 +87,12 @@ def get_app_name(text: str, max_len=20) -> str: ).lower() -def create_file(path: Path, content: str): +def create_file(path: Path, content: str) -> bool: if path.is_file(): - print(f"Application context file '{path}' already exists") - return + actions.app.notify(f"Application context file '{path}' already exists") + return False with open(path, "w", encoding="utf-8") as file: file.write(content) + + return True