From a89f2fd08cdd5d3e8a0f9c26dc676df38fedae91 Mon Sep 17 00:00:00 2001 From: Stephan Witt Date: Mon, 8 Aug 2022 10:36:46 +0200 Subject: [PATCH] Make "open -a" implicit on macOS Fix for bug #12570 - add simple check for app bundle name and prefix it with macOS open command if name matches --- src/support/Systemcall.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/support/Systemcall.cpp b/src/support/Systemcall.cpp index 6c96de1644..d339e11b80 100644 --- a/src/support/Systemcall.cpp +++ b/src/support/Systemcall.cpp @@ -217,6 +217,21 @@ string const parsecmd(string const & incmd, string & infile, string & outfile, } } else if (c == '<' && !(in_double_quote || escaped)) { o = 3; +#if defined (USE_MACOSX_PACKAGING) + } else if (o == 0 && i > 4 && c == ' ' && !(in_double_quote || escaped)) { + // if a macOS app is detected with an additional argument + // use open command as prefix to get it work + const size_t apos = outcmd[o].rfind(".app"); + const size_t len = outcmd[o].length(); + const bool quoted = outcmd[o].at(len - 1) == '"' && outcmd[o].at(0) == '"'; + const string & ocmd = "open -a "; + if (apos != string::npos && + (apos == (len - 4) || (apos == (len - 5) && quoted)) && + !prefixIs(trim(outcmd[o]), ocmd)) { + outcmd[o] = ocmd + outcmd[o]; + } + outcmd[o] += c; +#endif } else { if (escaped && in_double_quote) outcmd[o] += '\\'; -- 2.39.5