2

I have a pretty basic understanding of NSTask in Swift and can run a few commands in my program, but when I run open it says the file does not exist. I added the exact arguments that I use in the terminal, and I don't know what I'm missing. This is the code:

task.launchPath = "/usr/bin/open"
task.arguments = ["/Volumes/STS*/here.docx"]
task.launch()
task.waitUntilExit()

Thanks in advance. This is my first question, so have mercy if it's stupid.

Jean
  • 21
  • 1

1 Answers1

1

NSTask doesn't expand the * in your path. But if you invoke the command through the shell (i.e. /bin/bash), it will:

let task = NSTask()
task.launchPath = "/bin/bash"
task.arguments = ["-c", "open /Volumes/STS*/here.docx"]
task.launch()
task.waitUntilExit()

The -c option tell Bash to read the commands from a string. You can check the man page for more infor.

Code Different
  • 90,614
  • 16
  • 144
  • 163