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!