Applescript에서 메뉴 항목이 선택/초점되어 있는지 어떻게 알 수 있습니까?

StackOverflow https://stackoverflow.com/questions/69030

  •  09-06-2019
  •  | 
  •  

문제

모든 응용 프로그램의 도움말 메뉴에 있는 검색 상자에 초점을 맞추는 OS X 10.5용 스크립트가 있습니다.나는 그것을 키 조합에 두고 있으며 Spotlight와 마찬가지로 스크립트를 실행할 때 전환하기를 원합니다.따라서 검색 상자가 이미 입력에 초점이 맞춰져 있는지 확인하고, 그렇다면 도움말 메뉴를 클릭하는 대신 Esc를 입력하고 싶습니다.

현재 스크립트는 다음과 같습니다.

tell application "System Events"
    tell (first process whose frontmost is true)
        set helpMenuItem to menu bar item "Help" of menu bar 1
        click helpMenuItem
    end tell
end tell

그리고 나는 다음과 같은 것을 생각하고 있습니다.

tell application "System Events"
    tell (first process whose frontmost is true)
        set helpMenuItem to menu bar item "Help" of menu bar 1
        set searchBox to menu item 1 of menu of helpMenuItem
        if (searchBox's focused) = true then
            key code 53 -- type esc
        else
            click helpMenuItem
        end if
    end tell
end tell

...하지만 다음 오류가 발생합니다.

{응용 프로그램 "시스템 이벤트"의 응용 프로그램 프로세스 "스크립트 편집기" 메뉴 표시줄 1의 메뉴 표시줄 항목 "도움말"의 메뉴 항목 1}에 집중할 수 없습니다.

그렇다면 검색 상자에 이미 초점이 맞춰져 있는지 여부를 감지하는 스크립트를 얻을 수 있는 방법이 있습니까?


나는 내 문제를 해결했습니다. 그 주위에 작업.그래도 메뉴 항목이 선택되었는지 확인하는 방법을 모르므로 이 주제는 열어 두겠습니다.

도움이 되었습니까?

해결책

/Developer/Applications/Utilities/Accessibility Tools/Accessibility Inspector.app를 사용하면 내장된 접근성 시스템을 사용하여 마우스 아래에 있는 UI 요소의 속성을 볼 수 있습니다.요소와 새로 고침 버튼에 초점을 고정하려면 cmd-F7 작업을 특별히 기록해 두세요.안타깝게도 요소 및 속성 이름은 스크립트 모음의 이름과 직접 일치하지 않지만 시스템 이벤트에 대한 사전을 보거나 일반적으로 올바른 용어를 추측할 수 있습니다.

이를 사용하면 두 가지를 결정할 수 있습니다.첫째, focused 재산은 위에 있지 않습니다 menu item, 그러나 오히려 text fieldmenu item 그게 집중된 거죠.둘째, 메뉴 항목에는 selected 재산.

이를 통해 나는 다음을 생각해 냈습니다.

tell application "System Events"
    tell (first process whose frontmost is true)
        set helpMenuItem to menu bar item "Help" of menu bar 1

        -- Use reference form to avoid building intermediate object specifiers, which Accessibility apparently isn't good at resolving after the fact.
        set searchBox to a reference to menu item 1 of menu of helpMenuItem
        set searchField to a reference to text field 1 of searchBox

        if searchField's focused is true then
            key code 53 -- type esc
        else
            click helpMenuItem
        end if
    end tell
end tell

그래도 여전히 작동하지 않습니다.내가 알 수 있는 한 주요 이벤트가 실행되지 않으므로 뭔가 문제가 있을 수 있습니다. focused 텍스트 필드의 속성입니다.

어쨌든, 당신의 click 다시 한 번 해결책이 훨씬 쉬워 보입니다.

다른 팁

내장된 단축키 명령-? (Cmd-Shift-/) 이미 이와 같이 동작합니다.아직 초점이 맞춰져 있지 않은 경우 도움말 메뉴의 검색 필드로 키 초점을 이동하고, 그렇지 않으면 메뉴를 닫습니다.

속성을 사용해야 합니다. AXMenuItemMarkChar.

예:

tell application "System Events"
    tell process "Cisco Jabber"
        set X to (value of attribute "AXMenuItemMarkChar" of menu item "Available" of menu "Status" of menu item "Status" of menu "File" of menu bar item "File" of menu bar 1) is "✓" -- check if Status is "Availible"    
    end tell
end tell

메뉴 항목을 선택하면 반환 값은 다음과 같습니다. , 그렇지 않으면 missing value.

메모:이 테스트는 메뉴를 검사 중인 애플리케이션이 현재 실행 중인 경우에만 작동합니다. 가장 앞쪽.

방금 Illustrator에서 일부 파일 처리를 위해 이 작업을 직접 수행해야 한다는 사실을 발견했습니다.

내가 생각해낸 내용은 다음과 같습니다.

tell application "Adobe Illustrator"
activate
tell application "System Events"
    tell process "Illustrator"
        set frontmost to true
        set activeMenuItem to enabled of menu item "Unlock All" of menu "Object" of menu bar item "Object" of menu bar 1
        if activeMenuItem is true then
            tell me to beep 3
        else
            tell me to beep 2
        end if
    end tell
end tell
end tell

완료.

이는 문제 없이 작동했으며 파일을 반복하는 데 사용할 수 있었습니다.앞으로 자동화할 때 이 작업을 더 많이 해야 할 것 같습니다.

행운을 빌어요!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top