LaTeXTools icon indicating copy to clipboard operation
LaTeXTools copied to clipboard

Can view_command correctly handle quotations?

Open mil-ad opened this issue 7 years ago • 10 comments

So I'm trying to set up a new view_command for macOS to open PDFs using PDF Expert. My view_command looks like below but it doesn't work:

"osx" : {
     "view_command": "open -a \"PDF Expert\""
 },

When I replace it with "open -a Preview" it works fine so I guess it's something to do with the fact that the name of the app has spaces in it and needs to be in quotations.

I also tried "open -a PDF\ Expert" but it doesn't work either.

Am I doing something wrong?

mil-ad avatar Jul 20 '18 11:07 mil-ad

If I rename the app to PDFExpert and use "view_command": "open -a PDFExpert" then everything works fine so it must be something to do with the name.

mil-ad avatar Jul 20 '18 11:07 mil-ad

I strongly suspect this is due to the internal metadata PDF Expert reports to macOS. I can run open -a "Google Chrome" (for example) as a viewer command perfectly well. Unfortunately, I don’t have the $60 to install the app from the App Store and I’m not willing to run their installer on my machine so I can’t test this out, but I suspect you can use open -a PDFExpert without renaming the app and it will work.

ig0774 avatar Jul 20 '18 12:07 ig0774

Actually Google Chrome is a good example because that doesn't work for me either. Could you please share your viewer command for chrome?

mil-ad avatar Jul 20 '18 12:07 mil-ad

It's just this:

"viewer": "command",
"viewer_settings": {
	"osx": {
		"view_command": "open -a \"Google Chrome\""
	}
}

ig0774 avatar Jul 20 '18 23:07 ig0774

Interesting, that does not work for me.

mil-ad avatar Jul 21 '18 10:07 mil-ad

That's weird... Some questions / things to try:

  1. Do you use a shell other than bash? (If that question's meaningless to you, the answer is no).
  2. If you open the console you should see a line something like the one below. Do you see this line?
Running "open -a 'PDF Expert' /some/path/here"
  1. Does running open -a "PDF Expert" /path/to/your/pdffile.pdf do what you expect when run from the Terminal app?

ig0774 avatar Jul 23 '18 23:07 ig0774

  1. I use zsh. I tried spawning Sublime from bash but doesn't seem to make a difference
  2. I do: Running "open -a '"Google Chrome"' '/some/path/file.pdf'"
  3. Yes that works fine in a zsh terminal

Looking at the console, I think the problem is in those additional single quotes

mil-ad avatar Jul 24 '18 12:07 mil-ad

It's an issue with this line: https://github.com/SublimeText/LaTeXTools/blob/9aa34a033c3ea7fd649a0ee362f027aee0ab3cb4/viewers/command_viewer.py#L113

Here is some sample output:

>>> shlex.split("open -a \"Google Chrome\"", False, False)
['open', '-a', '"Google Chrome"']

You can use the following instead:

>>> shlex.split("open -a \"Google Chrome\"", False)
['open', '-a', 'Google Chrome']

Isolus avatar Sep 26 '18 11:09 Isolus

I'm also having this issue. Should I submit a PR with the fix @Isolus suggested?

nscaife avatar Dec 18 '18 17:12 nscaife

YES YES

mil-ad avatar Dec 18 '18 17:12 mil-ad