Applescript击键Filepath变量

时间:2016-02-11 15:05:02

标签: applescript automator

我正在尝试创建一个脚本,使用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

结束

1 个答案:

答案 0 :(得分:0)

这取决于input / theItem的等级。击键必须是textinput可以是任何内容。

尝试

keystroke (theItem as text)

keystroke (POSIX path of theItem)

System Events中相当于⇧⌘G

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