如何在AppleScript中区分多个java进程

时间:2013-01-24 08:57:07

标签: applescript osascript

写osascript时遇到问题。我需要“告诉”一个java进程(GUI)做某事但是还有其他java进程使用相同的进程名称“java”(也是GUI), 所以我的下面的示例代码对我不起作用:

  osascript \
    -e "tell application \"System Events\"" \
       -e "tell process \"java\"" \
          -e "click button \"MyButton\" of tab group 1 of window \"MyWindow\"" \
       -e "end tell" \
    -e "end tell"

所以我的问题是如何在这种情况下区分不同的java进程?

1 个答案:

答案 0 :(得分:0)

根据您对我的评论的回复,我会做类似以下的事情。请注意,我没有对此进行测试,因此您可能需要对其进行调整,但它会显示如何检查这些特定名称。祝你好运。

tell application "System Events"
    set javaProcesses to processes whose name is "java"
    repeat with aJavaProcess in javaProcesses
        tell aJavaProcess
            try
                set windowName to name of window 1
                set buttonNames to title of buttons of tab group 1 of window 1
                if windowName is "Java Control Panel" and "Update Now" is in buttonNames then
                    click (first button of tab group 1 of window 1 whose title is "Update Now")
                    exit repeat
                end if
            end try
        end tell
    end repeat
end tell

编辑 :也许你可以像这样进入正确的过程......

tell application "System Events"
    set javaIDs to unix id of processes whose name is "java"
    repeat with i from 1 to count of javaIDs
        set aJavaProcess to (first process whose unix id is (item i of javaIDs))
        tell aJavaProcess
            -- do the stuff in the tell block from the code above
        end tell
    end repeat
end tell