怎样才能重新启动搜索程序?
-
13-09-2019 - |
题
如果我OPTION + RIGHT CLICK
上的Finder图标,我得到的上下文菜单“的重新开张的”选项。我想以编程方式重新启动Finder中,如果在所有可能的。我敢肯定有一个更好的方式来做到这一点,而不是杀了它,让它重新启动。假设我有正确的授权/权限已经这样做了。
此外,我想重新启动聚光灯以及
解决方案
发送它使用AppleScript退出事件,则它发送一个激活事件:
//tell Finder to quit
NSAppleScript *restartFinder = [[NSAppleScript alloc] initWithSource:@"tell application \"Finder\" to quit"];
[restartFinder executeAndReturnError:nil];
编辑:添加一个延迟,以确保Finder是准备接收激活事件。在我的机器,有时需要这种延迟,有时没有:
//delay 1 second
restartFinder = [[NSAppleScript alloc] initWithSource:@"delay 1"];
[restartFinder executeAndReturnError:nil];
(...端EDIT)
//tell Finder to activate
restartFinder = [[NSAppleScript alloc] initWithSource:@"tell application \"Finder\" to activate"];
[restartFinder executeAndReturnError:nil];
其他提示
Finder是由系统维持生命,所以你可以杀了它,它会自动重新启动。我用killall Finder
做到这一点。
“重新启动]”几乎肯定仅仅发送一个终止信号给查找器。
与killall Finder
杀搜索工作,因为系统将自动重新启动它。
[[NSTask launchedTaskWithLaunchPath:@"/usr/bin/killall"
arguments:[NSArray arrayWithObjects:@"Finder", nil]] waitUntilExit];
不隶属于 StackOverflow