AppleScript - 문자열에 대한 결과를 검색하는 방법은 무엇입니까?

AppleScript - 문자열에 대한 결과를 검색하는 방법은 무엇입니까?

문자열이 나타나는지 확인하기 위해 AppleScript의 결과를 검색하려고 합니다.

이 코드를 실행하면:

tell application "System Events" to tell process "Box Sync" to ¬
    tell menu bar item 1 of menu bar 2
        click
        get menu items of menu 1
        set myStatus to menu items of menu 1
        set myResult to result
        return myResult             
    end tell

결과:

{menu item "Files Synced" of menu 1 of menu bar item 1 of menu bar 2 of application process "Box Sync" of application "System Events", menu item 2 of menu 1 of menu bar item 1 of menu bar 2 of application process "Box Sync" of application "System Events", menu item "Pause" of menu 1 of menu bar item 1 of menu bar 2 of application process "Box Sync" of application "System Events", menu item 4 of menu 1 of menu bar item 1 of menu bar 2 of application process "Box Sync" of application "System Events", menu item "Open Box Sync Folder" of menu 1 of menu bar item 1 of menu bar 2 of application process "Box Sync" of application "System Events", menu item "Open Box.com" of menu 1 of menu bar item 1 of menu bar 2 of application process "Box Sync" of application "System Events", menu item 7 of menu 1 of menu bar item 1 of menu bar 2 of application process "Box Sync" of application "System Events", menu item "Preferences…" of menu 1 of menu bar item 1 of menu bar 2 of application process "Box Sync" of application "System Events", menu item 9 of menu 1 of menu bar item 1 of menu bar 2 of application process "Box Sync" of application "System Events", menu item "Quit" of menu 1 of menu bar item 1 of menu bar 2 of application process "Box Sync" of application "System Events"}

이제 이 결과를 검색하여 "파일 동기화됨"이 있는지 확인하고 싶습니다. 그러나 실행 중

 myResult contains "Files Synced"

전체 결과의 인쇄물을 다시 제공합니다. 문자열이 존재하는지 확인하기 위해 이 결과를 어떻게 검색합니까?

답변1

return myResult첫 번째 실행 후 줄을 제거하지 않았기 때문에 두 번 모두 동일한 인쇄물을 얻었습니다 . return이 명령에 도달하면 항상 스크립트를 종료합니다.

▸ 추가로 다음을 변경하십시오.

    set myStatus to menu items of menu 1

이에:

    set myResult to name of menu items of menu 1

▸ 다음 줄을 삭제합니다.

    get menu items of menu 1

그리고 이 줄은:

    set myResult to result

(그들은 말 그대로 아무것도 하지 않습니다.)

최종 스크립트는 다음과 같습니다.

    tell application "System Events" to tell process "Box Sync" to ¬
        tell menu bar item 1 of menu bar 2
            click
            set myResult to name of menu items of menu 1
            myResult contains "Files Synced"
        end tell

true이는 또는 를 반환합니다 false.

또는 명시적인 변수 선언 없이(및 AppleScript 사전 정의 result변수 사용):

    tell application "System Events" to tell process "Box Sync" to ¬
        tell menu bar item 1 of menu bar 2
            click
            get the name of menu items of menu 1
            result contains "Files Synced"
        end tell

명확한 설명이 필요하거나 추가 문의사항이 있는 경우, 주저하지 말고 댓글을 남겨주시면 답변해 드리겠습니다. 문제를 해결하는 데 도움이 된다면 이를 허용된 답변으로 선택하는 것을 고려해 보십시오.

관련 정보