2017-03-10 3 views
0

question은 후속 질문을했습니다.AppleScript를 사용하여 XML에서 키/값 쌍을 찾으십니까?

UI 요소 (접근성 검사에서 표시하는 이름)의 이름을 입력하고이 요소의 키를 반환 할 수있는 짧은 Applescript를 만들고 싶습니다. 마지막 목적은 언어 설정이 다른 시스템에서 실행할 수있는 스크립트를 만드는 것입니다.

나는 이것을 달성하는 좋은 방법이 (XPaths?)가 될지 모르겠다. 그래서 질문은 꽤 열려있다. 멋진 UI가 필요 없으므로 스크립트 편집기에서 실행하고 싶습니다. 요소의 이름과 함께보고있는 응용 프로그램/번들의 이름을 수동으로 변경하면됩니다.

답변

1

당신은 이런 일을 할 수있는 : 당신은 정말 멋진 얻고 싶었다 경우

XML 파일 "strings.xml의"

<?xml version="1.0"?> 
<strings> 
    <string id="hello"> 
     <token lang="en">Hello world!</token> 
     <token lang="fr">Bonjour tout le monde!</token> 
    </string> 
    <string id="bye"> 
     <token lang="en">Goodbye!</token> 
     <token lang="fr">Au revoir!</token> 
    </string> 
</strings> 

애플 스크립트

set theKey to "bye" 
set theLang to "fr" 
tell application "System Events" 
    tell XML file "~/Desktop/strings.xml"'s XML element "strings" 
     tell (the first XML element whose id = theKey) 
      set theValue to value of first XML element whose XML attribute "lang"'s value is theLang 
     end tell 
    end tell 
end tell 
log theValue 

당신이 TMX format를 대신 사용할 수 있습니다 이 사용자 정의 XML의