0

I am trying to open applications using python. At the moment, this is what I have got:

os.system("open " + "/Applications/" + app + ".app")

('app' is a string with an appname, changes throughout the script)

Now, my problem is that this works flawlessly when I try to open apps with a single word for their name. Like "Blender" or "Brackets". However, if I try to open apps like photoshop (which in the applications folder are named "Adobe Photoshop CS6") nothing happens. I have been trying for several hours now, went through a lot of questions, many of them talking about adding an 'r' before the string. I have tried this before every part of my string, and also tried to encapsulate it all between quotes but nothing helps.

Why is this even an issue?

SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87
Robin
  • 360
  • 1
  • 2
  • 11
  • You're really executing a shell command. Guess what `open Adobe Photoshop CS6.app` means in the shell: 3 separate arguments. You need to quote/escape for shell syntax at the very least: `open 'Adobe Photoshop CS6.app'`. – deceze Jul 12 '16 at 13:52
  • Having said that, there's gotta be better ways to do this in Python than going through the shell. – deceze Jul 12 '16 at 13:53

1 Answers1

1

Add quotes around the .app bit:

os.system("open " + "'/Applications/" + app + ".app'")
                     ^                             ^

so it expands to:

open '/Application/Hello World.app'

You should probably be using subprocess.call() anyway, which accepts arguments in array elements and doesn't suffer from this issue.

Droppy
  • 9,691
  • 1
  • 20
  • 27