diff --git a/tagstudio/src/qt/ts_qt.py b/tagstudio/src/qt/ts_qt.py index 729f7657..d9bbccc1 100644 --- a/tagstudio/src/qt/ts_qt.py +++ b/tagstudio/src/qt/ts_qt.py @@ -14,6 +14,8 @@ import os import sys import time import traceback +import shutil +import subprocess from types import FunctionType from datetime import datetime as dt from pathlib import Path @@ -60,11 +62,20 @@ INFO = f'[INFO]' logging.basicConfig(format="%(message)s", level=logging.INFO) -def open_file(path): +def open_file(path: str): try: - os.startfile(path) - except FileNotFoundError: - logging.info('File Not Found! (Imagine this as a popup)') + if sys.platform == "win32": + subprocess.Popen(["start", path], shell=True, close_fds=True, creationflags=subprocess.DETACHED_PROCESS) + else: + if sys.platform == "darwin": + command_name = "open" + else: + command_name = "xdg-open" + command = shutil.which(command_name) + if command is not None: + subprocess.Popen([command, path], close_fds=True) + else: + logging.info(f"Could not find {command_name} on system PATH") except: traceback.print_exc()