0

编写 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进程?

4

1 回答 1

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
于 2013-01-25T02:05:30.867 回答