여기 AppleScript로 : 그것은 종료 할 때 응용 프로그램을 다시 시작 할 수 있도록
대신, 인스턴스의 terminated
속성을 모니터하기 위해 관찰 키 - 값을 사용하여이 문제를 관리 할 NSRunningApplication
클래스를 사용해야합니다 방법. 당신은 당신이 본 것처럼 특정 지연 시간에 의지 할 수 없습니다. 따라서 Finder가 실행중인 프로세스 목록에 있는지 검사하여 수동으로 Finder가 종료 될 때까지 기다립니다. 더 이상 목록에 없으면 종료되었음을 알게되고 다시 활성화 할 수 있습니다.
또한 반복 루프로 인해 스크립트에 시간 확인을 기록합니다. 무언가가 잘못되어 간다면 우리는 반복 루프가 영원히 돌아가는 것을 원하지 않습니다. 따라서 10 초 이상 실행하면 자동으로 반복 루프가 종료됩니다.
tell application "Finder" to quit
set inTime to current date
repeat
tell application "System Events"
if "Finder" is not in (get name of processes) then exit repeat
end tell
if (current date) - inTime is greater than 10 then exit repeat
delay 0.2
end repeat
tell application "Finder" to activate
다음은 해당 코드의 osascript 버전입니다.
/usr/bin/osascript -e 'tell application "Finder" to quit' -e 'set inTime to current date' -e 'repeat' -e 'tell application "System Events"' -e 'if "Finder" is not in (get name of processes) then exit repeat' -e 'end tell' -e 'if (current date) - inTime is greater than 10 then exit repeat' -e 'delay 0.2' -e 'end repeat' -e 'tell application "Finder" to activate'
임의의 "연결이 잘못되었습니다. -609"AppleScript 오류를 방지하기 위해 응용 프로그램 "Finder"에 지시 한 후에 지연이 필요합니까 ?? –
제 경험상 Finder가 너무 빨리 종료되어 다시 시작하려고 시도하면 임의 오류가 발생합니다. 따라서 시스템 이벤트를 사용하여 이러한 문제를 방지하기 위해 시스템 이벤트가 종료 될 때까지 기다립니다. 반복 루프에는 설명 된 내용을 막기위한 지연이 있습니다. 이론이 건실하다고 믿습니다. – regulus6633
종료하기 전에 지연이 필요합니까? –