2010-08-21 6 views
3

내 스크립트 중 일부를 실행 한 후 "제목 없음"창이있는 사파리 창을 여러 개 가져 왔습니다.applescript를 사용하여 여러 Safari 창 닫기

"Unitlted"라는 이름의 모든 창을 닫으려고했지만 오류 메시지와 함께 모든 것을 닫지 않습니다 -> "Safari에 오류가 발생했습니다 : 9 번 항목을 가져올 수 없습니다. 모든 창. 잘못된 색인입니다. " 모든 창을 닫으려면 여러 번 실행해야했습니다.

tell application "Safari" 
    repeat with w in windows 
     if name of w is "Untitled" then 
      tell w to close 
     end if 
    end repeat 
end tell 

무엇이 좋을까요?

답변

3

는 사용 AppleScript로 filter reference form는 :

tell application "Safari" 
    close (every window whose name is "Untitled") 
end tell 
2

문제는 창을 닫을 때 창 수가 바뀌고 결국 루프가 시작된 창 중 하나가 더 이상 존재하지 않기 때문입니다 (왜냐하면 루프 변수를 루프 중간).

이벤트 및 답장 로그를 켜면 상황을 좀 더 명확하게 볼 수 있습니다.

다음은 수정 사항입니다. 이것은 창이있는 것처럼 반복됩니다. 창 # 1이 제목없는 경우 닫힙니다. 그렇지 않다면 창 # 2를 계속 진행합니다.

tell application "Safari" 
    set windowNumber to 1 
    repeat the number of windows times 
     if name of window windowNumber starts with "Untitled" then 
      close window windowNumber 
     else 
      set windowNumber to windowNumber + 1 
     end if  
    end repeat 
end tell 

내 AppleScript로는 정말 녹슨입니다. 더 간단한 방법 (즉, 일종의 close all windows whos name starts with "Untitled" 구문)이 있다고 확신하지만이 방법이 효과적입니다.

0

이 나를 위해 작동합니다

tell application "Safari" 
    close (every tab of every window whose name starts with "some_text") 
end tell 

나 :

tell application "Safari" 
    close (every tab of every window whose URL contains "some_text") 
end tell