2013-02-24 2 views
0

내 스크립트는 AppA에서 텍스트를 가져와 AppB의 텍스트 편집에 붙여 넣습니다. AppB가 시작되면 (스크립트에 의해) 텍스트 편집이 비활성화되어 사용자가 작업을 수행 할 때 활성화됩니다. 그 행동은 수동으로해야합니다.AppleScript로 감지 된 편집 상자

스크립트는 사용자가 오류가 발생하기 전에 실행됩니다. 내 생각은 편집 활성화되어 있는지 확인했지만이 오류가 발생합니다. 응용 프로그램 "시스템 이벤트"의 "AppB 창"을 가져올 수 없습니다. 응용 프로그램 "시스템 이벤트"의 AppB 창을 가져올 수 없습니다. 오류가 한 번만 발생합니다.

어떻게하면 오류를 피할 수 있습니까? ?

on idle 
tell application "System Events" to set AppAIsOpen to (application process "AppA" exists) 
if (AppAIsOpen) then 
    set AppAWasOpen to true 
    tell application "AppA" 
    set hdg to TxRprt 
    set beam to hdg as string 
    end tell 
    if ((count beam) < 3) then set beam to text -3 thru -1 of ("000" & beam) 
    if (beam is not previousText) then 
     tell application "AppB" to launch 
     tell application "System Events" 
      tell application process "AppB" 
     if text field 1 of window "AppB" is enabled then -- error here 
      set value of text field 1 of window "AppB" to beam --or here 
     end if 
     end tell 
    end tell 
    set previousText to beam 
     end if 
    return checkInterval 
else if (AppAgWasOpen) then 
    quit 
     return 1 
end if 

답변

1

은 일반적으로 내가 반복 루프를 입력하고 텍스트 필드 (또는 인터페이스 요소) 그것으로 아무것도하기 전에 가능하게 될 때까지 확인 유휴 끝. 이런 식으로 뭔가가 작동하고해야 할 오류를 제거하십시오.

아니요 ice 또한 반복 과정에 걸리지 않도록이 과정에 시간 확인을 추가합니다. 이 경우 텍스트 필드를 사용하려면 최대 5 초 동안 기다려야합니다.

tell application "System Events" 
    -- wait for the text field to become available 
    set startTime to current date 
    repeat until exists (text field 1 of window "AppB" of application process "AppB") 
     if (current date) - startTime is greater than 5 then 
      error "Could not find text field 1 of window AppB of application process AppB" 
      exit repeat 
     end if 
     delay 0.2 
    end repeat 

    tell application process "AppB" 
     if text field 1 of window "AppB" is enabled then -- error here 
      set value of text field 1 of window "AppB" to beam --or here 
     end if 
    end tell 
end tell 
+0

멋지게 작동합니다. 감사. – Mike