Skip to content

Commit b9b2361

Browse files
authored
Merge pull request #43 from xarvex/file-open-1
Allow files to be opened in their respective programs in the background for Windows, MacOS, and Linux
2 parents 6e7567a + 956ffd4 commit b9b2361

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

tagstudio/src/qt/ts_qt.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
# from typing_extensions import deprecated
4242
from humanfriendly import format_timespan
4343
# from src.qt.qtacrylic.qtacrylic import WindowEffect
44+
import shutil
45+
import subprocess
4446

4547
# SIGQUIT is not defined on Windows
4648
if sys.platform == "win32":
@@ -56,11 +58,20 @@
5658
logging.basicConfig(format="%(message)s", level=logging.INFO)
5759

5860

59-
def open_file(path):
61+
def open_file(path: str):
6062
try:
61-
os.startfile(path)
62-
except FileNotFoundError:
63-
logging.info('File Not Found! (Imagine this as a popup)')
63+
if sys.platform == "win32":
64+
subprocess.Popen(["start", path], shell=True, close_fds=True, creationflags=subprocess.DETACHED_PROCESS)
65+
else:
66+
if sys.platform == "darwin":
67+
command_name = "open"
68+
else:
69+
command_name = "xdg-open"
70+
command = shutil.which(command_name)
71+
if command is not None:
72+
subprocess.Popen([command, path], close_fds=True)
73+
else:
74+
logging.info(f"Could not find {command_name} on system PATH")
6475
except:
6576
traceback.print_exc()
6677

0 commit comments

Comments
 (0)