하나의 다시 시작 파인더가 프로그래밍 방식으로 어떻게 작동합니까?

StackOverflow https://stackoverflow.com/questions/1462425

문제

만약 내가 OPTION + RIGHT CLICK 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];

(... 종료 편집)

//tell Finder to activate
restartFinder = [[NSAppleScript alloc] initWithSource:@"tell application \"Finder\" to activate"];
[restartFinder executeAndReturnError:nil];

다른 팁

파인더는 시스템에 의해 살아 있으므로 시스템을 죽일 수 있으며 자동으로 다시 시작됩니다. 나는 사용한다 killall Finder 이것을 달성하기 위해.

'다시 시작'은 거의 확실히 파인더에게 킬 신호를 보냅니다.

살해 파인더 killall Finder 시스템이 자동으로 다시 시작되므로 작동합니다.

[[NSTask launchedTaskWithLaunchPath:@"/usr/bin/killall" 
    arguments:[NSArray arrayWithObjects:@"Finder", nil]] waitUntilExit];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top