1

I am trying to kill Finder so it restarts after I make a change using NSTask(). Below is what I am trying to do at the moment in Swift, the problem is I am getting an error and I can't work out how to fix it.

Code:

var task = NSTask()
task.launchPath = "/usr/bin/defaults"
task.arguments = ["write", "com.apple.finder", "AppleShowAllFiles", "YES"]
task.launch()
task.waitUntilExit()

var taskKill = NSTask()
taskKill.launchPath = "/usr/bin/killall"
taskKill.arguments = ["Finder"]
taskKill.launch()

And the error I am getting:

killall: warning: kill -TERM 5185: Operation not permitted

I have searched all over the internet for a solution to this. Some suggested turning on Sandbox which I did and nothing changed, and some said that I need to get permission from the user which is a poorly documented part of OS X and is hard to do.

If anyone knows how I can restart Finder in OS X (preferably Swift), please answer, even if it's just a link to some documentation or anything that will help me do this.

Thanks!

  • In what context are you using this? Because I just tried in a sample app and it worked (10.10, Xcode 6, no Sandbox). – Eric Aya Aug 28 '15 at 17:11
  • When I tried to submit my app to iTunes connect, and did one final test it started to give me the error. I am just using it as it is in the code in my question. I simple have to set show files to yes then refresh finder. I have been reading that this isn't technically 'allowed' in Swift, so I have to find another way of doing it. – manwholikesspritekit Aug 28 '15 at 17:46
  • Did you manage to get this to work? – damjandd Oct 14 '17 at 19:55

0 Answers0