我有一个应用程序,需要重新启动码头应用程序。我已经尝试过这两个苹果脚本:
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)")
}..。和NSTask:
let task = NSTask()
task.launchPath = "/usr/bin/killall"
task.arguments = ["Dock"]
task.launch()..。和另一个NSTask
func restartFinder () {
let task = NSTask()
task.launchPath = "/bin/bash"
task.arguments = ["killall Dock"]
task.launch()
}然而,我的应用程序似乎不允许重新启动它。我想将我的应用程序发布到AppStore,但是如何重新启动这个端口呢?
使用Apple脚本时出错:
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}";
}使用NSTask时出错
killall: warning: kill -TERM 255: Operation not permitted更新
我也在STPrivilegedTask上试过,这对我来说也不管用。我也没有得到一扇窗户。
发布于 2015-07-14 22:04:43
我会尝试使用Applescript,但如下所示:
var errorDict: NSDictionary? = nil
let appleScript = NSAppleScript(source: "do shell script \"killall Dock\" with administrator " +
"privileges")
var error = appleScript?.executeAndReturnError(&errorDict)
if let errorDict = errorDict {
println("An error occured: \(errorDict)")
}通过这种方式,它以管理权限执行shell脚本(就像通过终端)。问题是,由于这是一个通常只由系统或用户完成的任务,因此需要输入管理密码。
https://stackoverflow.com/questions/31417055
复制相似问题