Fix open in Preview for macOS

This commit is contained in:
Micah Lee 2021-07-02 13:48:20 -07:00
parent babcd62071
commit 3f76211459
No known key found for this signature in database
GPG key ID: 403C2657CD994F73

View file

@ -46,35 +46,34 @@ class GuiCommon(object):
return QtGui.QIcon(path) return QtGui.QIcon(path)
def open_pdf_viewer(self, filename): def open_pdf_viewer(self, filename):
if self.global_common.settings.get("open_app") in self.pdf_viewers: if platform.system() == "Darwin":
if platform.system() == "Darwin": # Open in Preview
# Open in Preview args = ["open", "-a", "Preview.app", filename]
args = ["open", "-a", "Preview.app", filename]
# Run # Run
args_str = " ".join(pipes.quote(s) for s in args) args_str = " ".join(pipes.quote(s) for s in args)
print(Fore.YELLOW + "> " + Fore.CYAN + args_str) print(Fore.YELLOW + "> " + Fore.CYAN + args_str)
subprocess.run(args) subprocess.run(args)
elif platform.system() == "Linux": elif platform.system() == "Linux":
# Get the PDF reader command # Get the PDF reader command
args = shlex.split( args = shlex.split(
self.pdf_viewers[self.global_common.settings.get("open_app")] self.pdf_viewers[self.global_common.settings.get("open_app")]
) )
# %f, %F, %u, and %U are filenames or URLS -- so replace with the file to open # %f, %F, %u, and %U are filenames or URLS -- so replace with the file to open
for i in range(len(args)): for i in range(len(args)):
if ( if (
args[i] == "%f" args[i] == "%f"
or args[i] == "%F" or args[i] == "%F"
or args[i] == "%u" or args[i] == "%u"
or args[i] == "%U" or args[i] == "%U"
): ):
args[i] = filename args[i] = filename
# Open as a background process # Open as a background process
args_str = " ".join(pipes.quote(s) for s in args) args_str = " ".join(pipes.quote(s) for s in args)
print(Fore.YELLOW + "> " + Fore.CYAN + args_str) print(Fore.YELLOW + "> " + Fore.CYAN + args_str)
subprocess.Popen(args) subprocess.Popen(args)
def _find_pdf_viewers(self): def _find_pdf_viewers(self):
pdf_viewers = {} pdf_viewers = {}