I have an app that needs to restart the dock application. I have tried this with both Apple Script:
var errorDict: NSDictionary? = nil
let appleScript = NSAppleScript(source: "tell application \"Dock\" to quit")
var error = appleScript?.executeAndReturnError(&errorDict)
if let errorDict = errorDict {
println("An error occured: \(errorDict)")
}
... and NSTask
:
let task = NSTask()
task.launchPath = "/usr/bin/killall"
task.arguments = ["Dock"]
task.launch()
... and another NSTask
:
func restartFinder () {
let task = NSTask()
task.launchPath = "/bin/bash"
task.arguments = ["killall Dock"]
task.launch()
}
However, it seems my app is not allowed to restart it. I'd like to release my app to the AppStore, but how can I restart the dock?
Error when using Apple Script:
An error occured: {
NSAppleScriptErrorAppName = Dock;
NSAppleScriptErrorBriefMessage = "Application isn\U2019t running.";
NSAppleScriptErrorMessage = "Dock got an error: Application isn\U2019t running.";
NSAppleScriptErrorNumber = "-600";
NSAppleScriptErrorRange = "NSRange: {27, 4}";
}
Error when using NSTask
:
killall: warning: kill -TERM 255: Operation not permitted
Update
I have also tried it with STPrivilegedTask, which didn't work for me either. Neither did I get an auth window.