2017-09-26 21 views
1

정확한 수에 대한 값을 확인하려고하지만 스테핑 프로세스에 문제가 있습니다. 감안할 때 :AppleScript에서 점선으로 증가합니까?

1-1 
2-1 
3-1 
4-1 
5-1 
6-1 
7-1 
7-2 
8-1 
9-1 
9-2 
9-3 
9-4 
10-1 
11-1 
12-2 ## intentionally left out 12-1 to throw error 
13-1 

목록에서 제대로 증가하고 플래그가없는 경우 어떻게 할 수 있습니까? 내 스크립트를 실행하면 그것은 7-2 통해 실행하지만 8-1에 관해서는 실패합니다

아이 마커가없는 것으로 보인다.

코드 : 애플 스크립트에서

tell application "BBEdit" 
    activate 
    set parentCount to 1 
    set childCount to 1 
    set theDoc to text document 1 
    select insertion point before first character of theDoc 
    set searchOpt to {search mode:grep, wrap around:false} 
    repeat 
     set theNumbers to find "^(\\d{1,4})-(\\d{1,4})" searching in text 1 of theDoc options searchOpt with selecting match 
     if not found of theNumbers then exit repeat 
     set parentNum to (grep substitution of "\\1") as number 
     set childNum to (grep substitution of "\\2") as number 
     if parentNum is equal to parentCount and childNum is equal to childCount then 
      set parentCount to parentCount + 1 
     else if parentNum is equal to parentCount and (childNum + 1) is equal to childCount then 
      set parentCount to parentCount + 1 
      set childCount to 1 
     else 
      display dialog "missing marker" 
     end if 
    end repeat 
    display dialog "completed check" 
end tell 

가 어떻게 제대로 숫자의 순서를 증가 할 수 있습니까? 스크립트가이 두 조건문에 parentCount을 증가 시키며, 스크립트가 결코 childCount을 증가하지 않기 때문에 조건문에서

답변

0

, 당신은 동일한 조건 if parentNum is equal to parentCount를 사용, 두 번째 조건문은 작동하지 않습니다.

사용이 스크립트 :

tell application "BBEdit" 
    activate 
    set parentCount to 0 
    set childCount to 1 
    set theDoc to text document 1 
    select insertion point before first character of theDoc 
    set searchOpt to {search mode:grep, wrap around:false} 
    repeat 
     set theNumbers to find "^(\\d{1,4})-(\\d{1,4})" searching in text 1 of theDoc options searchOpt with selecting match 
     if not found of theNumbers then exit repeat 
     set parentNum to (grep substitution of "\\1") as number 
     set childNum to (grep substitution of "\\2") as number 
     if parentNum = (parentCount + 1) and childNum = 1 then -- if the parentNum increase of 1, the childNum must be 1 
      set parentCount to parentCount + 1 
      set childCount to 1 -- so, reset the childCount to 1 
     else if parentNum = parentCount and childNum = (childCount + 1) then 
      set childCount to childNum 
     else 
      display dialog "missing marker" 
      set parentCount to parentNum -- start at this value for the next sequence 
      set childCount to childNum -- start at this value for the next sequence 
     end if 
    end repeat 
    display dialog "completed check" 
end tell