10

開いているすべてのウィンドウのサイズを変更する AppleScript スクリプトを作成しようとしています。すべてのウィンドウに到達していることを確認するために、スクリプトにアプリケーションの名前と、そのアプリケーションで開いているウィンドウの数を表示させています。
興味深いことに、開いているすべてのアプリケーションの名前が聞こえますが、スクリプトでは、すべてのアプリケーションで開いているウィンドウが 0 であると表示されます。この問題を解決するにはどうすればよいですか?

これが私のコードです:

tell application "System Events"
    repeat with theProcess in (every process)
        if background only of theProcess is false then
            if name of theProcess is not "Finder" then
                if name of theProcess is "Google Chrome" then
                    say "Chrome woo hoo"
                    say (count windows as string)
                else
                    say name of theProcess as string
                    say (count windows as string)
                    tell theProcess
                        repeat with theWindow in windows
                            say "found a window of"
                            say (name of theProcess) as string
                            tell theWindow
                                click button 2
                            end tell
                        end repeat
                    end tell
                end if
            end if
        end if
    end repeat
end tell

私はMac OS X 10.7.5を使用しており、automator 2.2.4を使用してこのapplescriptを作成/実行しています

4

2 に答える 2

6

ウィンドウをカウントするようにプロセスに指示する必要があります。結局のところ、システムイベントではなく、ウィンドウについて知っているのはプロセスです。

プロセスにその名前を言うように指示しました。たとえば、「プロセスの名前を文字列として言う」などですが、使用するのは「say(ウィンドウを文字列として数える)」だけです...プロセスはそれに関連付けられていません。「プロセスのウィンドウを数える」を試してください。基本的に、プロセスを指示する場合と、指示しない場合と、すでにプロセスを指示しているにもかかわらずプロセスを指示する場合があるため、2回実行します。ここに「say(name of theProcess)as string」がありますが、そのコードは「tell theProcess」ブロック内にあるため、すでにtheProcessに通知されています。

本当にあなたはあなたのコードを調べて、より正確にする必要があります。ヒント...ウィンドウ内のボタンをクリックする場合は、ウィンドウが画面の最前面にある必要があります。そうしないと、クリックできません。もう1つのヒント...「名前」はすでに文字列であるため、文字列に強制する必要はありません。

ちなみに、私はあなたの投稿に対するMichaelDautermannのコメントに同意します...あなたがアクセスできないプロセスがあります。しかし、あなたは進歩するにつれてそれを見つけるでしょう。

これが私があなたのコードを書く方法です。基本的に、「tell theProcess」ブロックを使用して、最初にすべての変数を取得します。次に、それらの変数を使用して処理を実行できます。それがお役に立てば幸いです。プロセスを最前面にのみ作成したことに注意してください。つまり、複数のウィンドウが開いている場合は、前面ウィンドウのボタンをクリックするだけです。ボタンをクリックする前に、各ウィンドウを前面に表示するコードを追加する必要があります。幸運を。

tell application "System Events"
    repeat with theProcess in processes
        if not background only of theProcess then
            tell theProcess
                set processName to name
                set theWindows to windows
            end tell
            set windowsCount to count of theWindows

            if processName is "Google Chrome" then
                say "Chrome woo hoo"
                say windowsCount as text
            else if processName is not "Finder" then
                say processName
                say windowsCount as text
                if windowsCount is greater than 0 then
                    repeat with theWindow in theWindows
                        say "found a window of " & processName
                        tell theProcess
                            set frontmost to true
                            tell theWindow
                                click button 2
                            end tell
                        end tell
                    end repeat
                end if
            end if
        end if
    end repeat
end tell
于 2013-01-27T22:04:36.193 に答える