1

So I installed Miniconda using Homebrew and then installed Spyder using Conda. Then I wanted to make the process more "Mac" friendly by creating an application which opens Spyder so I used the solution by topoman which is below the accepted answer in this link:

Ways to invoke python and Spyder on OSX

Everything works more or less fine except I have ran into two issues (the second one isn't really an issue and more of an aesthetic related thing):

  1. I downloaded py files from this GitHub (https://github.com/realpython/python-scripts) just to test that it will open py files. It works for them and I am also able to set Spyder as the default application by using the "SpyderOpener" solution provided by topoman in the above link.

The issue is that when I create a new file in spyder and save it then try to click-open it, it won't. I'm not sure what the difference is and why the "SpyderOpener" does not work on this py file originating from Spyder, but works fine for the ones I downloaded.

  1. I was curious if it is possible to change the display icon for py files that have the default as "SpyderOpener". I did change the icon for the SpyderOpener application but it doesn't work. The icons for the files is just a blank printer sheet.

UPDATE:

I believe I found the issue. It depends on where the file is. When I put it on my desktop, no issue. When I put it in other certain places no issue. Based on experimenting it seems that the opener does not work when the file is within a folder that has a space in the name (e.g. folder name). The minute I change to folder_name or foldername it works fine.

Therefore, is someone able to explain why the opener script breaks down when there is a space at any place in the file path? Can the script be edited to handle this?

Does it boil down to the following stack threads (i.e. I need to apply double quotes somewhere in the script):

Shell Script and spaces in path

https://askubuntu.com/questions/1081512/how-to-pass-a-pathname-with-a-space-in-it-to-cd-inside-of-a-script

This thread also suggests the script shouldn’t use the $@ argument unquoted because it will break as soon as you have “spaces or wildcards”:

https://unix.stackexchange.com/questions/41571/what-is-the-difference-between-and

Therefore looking at the script and previous steps you have:

#!/bin/bash
/usr/local/bin/spyder $@

Then the opener script has:

for f in "$@"
do
    open /Applications/spyder.app --args $f
done
if [ -z "$f" ]; then
    open /Applications/spyder.app --args ~
fi

As for the rest of the script, I assume $f isn’t going to cause problems? Anyways, it seems the issue comes from the initial setup?

Based on this, it should be handled by the above line:

Handle whitespaces in arguments to a bash script

So is it breaking down because of the args?

  • What is the script or code that is giving errors. You did give some links, but difficult to discern where your code is. – Richard Barber Nov 01 '19 at 04:03
  • @RichardBarber I just edited the OP to provide the full script. A person elsewhere pointed out for —args $f maybe that’s the problem and needs to be changed to “$f”, but I tried and it didn’t work. – primordial2 Nov 01 '19 at 04:06
  • Keep in mind `“$f”` is not the same as `"$f"` (curly quotes don't work like straight quotes) – Richard Barber Nov 01 '19 at 04:13
  • 1
    @RichardBarber yeah sorry I’m on mobile right now, but I checked my edit of the script and it has straight quotes. – primordial2 Nov 01 '19 at 04:15
  • In that case I would try `"${f}"` – Richard Barber Nov 01 '19 at 04:36
  • @RichardBarber didn’t work. But I figured it out due to another user elsewhere. The other part of the set-up needs to be .../bin/spyder "$@" in addition to "$f" no curly braces needed. – primordial2 Nov 01 '19 at 04:42

0 Answers0