Applescript 击键文件路径变量

Applescript keystroke Filepath variable

我正在尝试创建一个脚本,该脚本将使用 Applescript 和 Automator 为我上传产品。当脚本在遍历我的列表时尝试使用变量作为文件路径时出现错误。代码如下。我还将一个文件夹的内容从 automator 输入到这个脚本中。错误在第 22 行。此外,如果您可以帮助处理第 42 行的第二次击键,它需要在不同的文件夹中重复重复。提前致谢!

on run {input, parameters}

repeat with theItem in input
    tell application "Safari"
        do JavaScript "document.getElementsByClassName('btn-com btn-info btn-large btn-icon-left add-product-button')[0].click();" in document 1
        delay 1
        do JavaScript "document.getElementsByClassName('btn-com btn-info btn-large btn-icon-left add-product-button')[0].click();" in document 1
        delay 1
        do JavaScript "document.getElementById('editor_commerce_product_short_description').innerHTML = 'All photos include full rights to the image and arrive via email. Comes in full 4K resolution. Image displayed is 1080P resolution. Orders may take up to 2 hours to be delivered. Watermarks will be removed!';" in document 1
        delay 1
        do JavaScript "document.getElementById('editor_commerce_product_price').value = '1.99';" in document 1
        do JavaScript "document.getElementsByClassName('btn dropdown-toggle selectbox-display')[0].click();" in document 1
        do JavaScript "document.getElementsByClassName('selectbox-content')[1].click();" in document 1
        do JavaScript "document.getElementsByClassName('w-upload-input')[2].click();" in document 1
    end tell

    delay 1

    tell application "System Events"
        keystroke "G" using {command down, shift down}
        delay 1
        keystroke theItem
        delay 1
        keystroke return

        delay 1
        keystroke return

        delay 1

    end tell

    delay 60

    tell application "Safari"
        do JavaScript "document.getElementsByClassName('w-upload-input')[1].click();" in document 1
    end tell

    tell application "System Events"
        keystroke "G" using {command down, shift down}
        delay 1
        keystroke "~/Desktop/Test_Samples/Test_1.png"
        delay 1
        keystroke return

        delay 1
        keystroke return

        delay 1

    end tell

    tell application "Safari"
        do JavaScript "document.getElementsByClassName('save-product btn-com btn-success')[0].click();" in document 1
    end tell
end repeat

return input

结束运行

取决于input / theItem的class。击键必须是textinput可以是任何东西。

尝试

keystroke (theItem as text)

keystroke (POSIX path of theItem)

而在 System Events⇧⌘G 等价于

keystroke "g" using {command down, shift down}