2011-09-08 5 views
9

Mac用Twitterのキャッシュを空にしてアプリを再起動するAppleScriptを作成しようとしています。私が実行している問題は、確認ダイアログに名前(タイトルバーが空)がないため、どのようにコンテキストを指定しないでボタンをターゲットにするかが分かりません。ここで私がこれまで持っているものです。AppleScriptを使用する名前/タイトルのないウィンドウ内のダイアログ内のボタンをクリックするにはどうすればよいですか?

tell application "Twitter" 
    activate 
end tell 
tell application "System Events" 
    tell process "Twitter" 
     tell menu bar 1 
     tell menu bar item "Twitter" 
      tell menu "Twitter" 
       click menu item "Empty Cache" 
      end tell 
     end tell 
     end tell 
    end tell 
end tell 
tell application "System Events" 
    click button "Empty Cache" of window "Empty Cache?" 
end tell 
tell application "Twitter" 
    quit 
end tell 
tell application "Twitter" 
    activate 
end tell 
+1

をあなたは、ウィンドウのタイトルを指定する必要はありません(あなたがしなければ、それは良いでしょうが)。あなたはちょうど 'ボタンをクリックすることができます"ウィンドウ1の空のキャッシュ " – fireshadow52

+1

あなたが望むなら、あなたは' ...フロントウィンドウの 'を行うことさえできます。 – fireshadow52

答えて

7

オブジェクト階層内のオブジェクトを参照するための多数の方法があります。名前は、一方向のみ(AppleScript Language Guide: Reference Formsを参照してくださいあなたのスクリプトは、すでに他の方法のいずれかを使用している:。Index

(多くのプログラミング言語とは異なり、AppleScriptでは、リスト内の項目が1ではなく0から始まるインデックス化されている)以下のスクリプトは、あなたが望むものを達成する必要があります:。

そのインデックスでメニューバーを参照することだ
tell menu bar 1 

tell application "Twitter" to activate 

tell application "System Events" 
    tell application process "Twitter" 
     click menu item "Empty Cache" of menu "Twitter" of menu bar item "Twitter" of menu bar 1 
     delay 1 
     --click button "Empty Cache" of front window 
     click button "Empty Cache" of window 1 
    end tell 
end tell 

tell application "Twitter" 
    quit 
    delay 1 
    activate 
end tell 

delay 1行はコメントアウトできます。私はプロシージャを遅くするためにそれらを追加したので、あなたは何が起こっているかをより簡単に見ることができます。

AppleScriptを使用してアプリケーション内のオブジェクトを「取得」する方法を理解しようとするとき、AppleScriptエディタを使用して、アプリケーションに関する詳細情報を見つけようとするクエリスクリプトを作成すると便利です。たとえば、TwitterではTwitter> Empty Cacheを選択して、Empty Cacheウィンドウを開きました。私は、次のスクリプトを実行しました:

tell application "Twitter" 
    set theWindows to every window -- get a list of windows 
    (* turns out there's only one window listed, 
     so get the first item in the list *) 
    set theWindow to first item of theWindows 
    -- get the properties of the window 
    properties of theWindow 
end tell 

このスクリプトは、次のような結果が返さ:

{closeable:true, zoomed:false, class:window, index:1, 
    visible:true, name:missing value, miniaturizable:true, 
id:28551, miniaturized:false, resizable:true, 
bounds:{-618, 76, -128, 756}, zoomable:true} 
関連する問題