Jean
Jean

Reputation: 21

using open command with NSTask

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.

Upvotes: 2

Views: 749

Answers (1)

Code Different
Code Different

Reputation: 93151

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.

Upvotes: 1

Related Questions