2017-03-10 10 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> 

のAppleScript

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の一覧

関連する問題