2012-09-19 4 views
1

로그인 할 때보다 스크립트가 있습니다. 사용자가 영화를보고 싶어하는지 묻습니다. 대부분의 경우 잘 작동합니다. 그러나 경우에 따라 알 수없는 이유로 AppleEvent 핸들러 오류가 발생합니다. 이 오류에 대한 다른 게시물을 읽었지만 모두 고유 한 것처럼 보입니다. 가능한 한 누군가가 제 스크립트를 살펴보고 이것이 때때로 나타나는 이유와 그것을 막기 위해 할 수있는 일이 있다면 말해주십시오.AppleScript - AppleEvent 핸들러가 실패했습니다.

알아두면 도움이되는 한 가지 점은이 오류가 발생할 때 스크립트에서 한 가지 실패한 것이 영화가 재생되지 않는다는 것입니다. 그것은 퀵타임에서 시작되지만 시작되지 않습니다.

미리 감사드립니다. 다음은 스크립트입니다.

tell application "Welcome" to activate 
set question to display dialog "Would you like a welcome video?" buttons {"No, I've seen it", "Yes, please"} default button 2 
set answer to button returned of question 
if answer is equal to "Yes, please" then tell application "QuickTime Player" 
    set theMovie to "Macintosh HD:Library:Desktop Pictures:Mac ML Opening Chalkbaord Video.mov" 
    set openMovie to open theMovie 
    present openMovie 
    play openMovie 
    delay 30 
    quit 
end tell 
if answer is equal to "No, I've seen it" then tell application "Welcome" 
    quit 
    tell application "System Events" 
     delete login item "Welcome" 
    end tell 
end tell 
+0

어떤 경우입니까? 어떤 맥락은 먼 길을 갈 수 있습니다. 컨텍스트와 조건에 대한 더 많은 통찰력을 얻을 때 질문을 편집 할 준비를하십시오. –

답변

1

제 생각 엔 영화를 열고 재생할 때까지 지연이 필요합니다. 때로는 코드가 컴퓨터가 반응 할 수있는 것보다 빠르게 실행됩니다. 그렇다면 코드가 동영상이 재생하도록 지시 할 때 동영상이 계속 열려 있기 때문에 오류가 발생할 수 있습니다. 따라서 코드의 다음 단계로 진행하기 전에 사용할 수 있는지를 확인하는 2 개의 반복 루프를 추가했습니다. 또한 "열기"대신 "파일 열기"가 필요합니다.

응용 프로그램에 무언가를 수행하라는 if 문에서 사용자의 접근 방식은 일반적이지 않습니다. 나는 그렇게하지 않을 것이다. 또한 if 문을 if/else if 문으로 결합합니다. 어쨌든, 여기 당신의 코드를 작성하는 방법이 있습니다 (저는 애플리케이션 "Welcome"가 코드 자체라고 가정합니다). 이게 도움이 되길 바란다!

set theMovie to "Macintosh HD:Library:Desktop Pictures:Mac ML Opening Chalkbaord Video.mov" 

tell me to activate 
set question to display dialog "Would you like a welcome video?" buttons {"No, I've seen it", "Yes, please"} default button 2 
set answer to button returned of question 

if answer is equal to "Yes, please" then 
    tell application "QuickTime Player" 
     activate 
     set openMovie to open file theMovie 

     -- delay until the movie opens 
     set startTime to current date 
     repeat until exists document 1 
      delay 0.2 
      if (current date) - startTime is greater than 10 then return -- a precaution so you don't get stuck in the repeat loop forever 
     end repeat 

     present openMovie 
     play openMovie 

     -- delay until the movie stops playing 
     repeat until document 1 is not playing 
      delay 1 
     end repeat 

     quit 
    end tell 
else if answer is equal to "No, I've seen it" then 
    tell application "System Events" to delete login item "Welcome" 
end if 
+0

그것은 절대적으로 환상적으로 작동했습니다! 나는 너에게 커피 또는 맥주를 살 수 있었으면 좋겠다! 내 대본에서 알 수 있듯이 나는 위험 할만큼 충분히 알기 때문에 이상한 "if"문을 사용한다. 고마워요, 고마워요! – Chuck