在Safari的特定进程ID上运行Javascript

时间:2015-02-24 09:42:43

标签: macos safari applescript

我在这里有这样的剧本:

on run argv
    set pid to item 1 of argv
    set fileLocation to item 2 of argv
    tell application "System Events"
        set theprocs to every process whose unix id is pid
        repeat with proc in theprocs
            set the frontmost of proc to true
            using terms from application "Safari"
                set theScript to "document.querySelector(\"input[name='fileField']\").click()"
                tell application "Safari" to do JavaScript theScript in current tab of first window
            end using terms from
            tell proc
                keystroke "G" using {command down, shift down}
                delay 2
                key code 51
                delay 2
                keystroke fileLocation
                delay 10
                key code 52
                delay 5
                key code 52
                delay 5
            end tell
        end repeat
    end tell

end run

尝试在Safari浏览器上执行文件上载过程。主要目标是针对给定的进程ID运行脚本(因为许多Safari将在计算机上运行)。

我的问题来自do JavaScript来自:

tell application "Safari" to do JavaScript theScript in current tab of first window

这是在不同的Safari浏览器上执行点击调用,而不是pid中给出的点击调用。

我只想确保脚本针对给定的Safari PID运行。

我该怎么做?

0 个答案:

没有答案