【问题标题】:Applescript keystroke Filepath variableApplescript 击键文件路径变量
【发布时间】:2016-05-22 10:29:13
【问题描述】:

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

结束运行

【问题讨论】:

    标签: applescript automator


    【解决方案1】:

    这取决于input / theItem 的类。击键必须是textinput 可以是任何值。

    试试

    keystroke (theItem as text)
    

    keystroke (POSIX path of theItem)
    

    而在System Events 中,⇧⌘G 的等价物是

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

    【讨论】:

    • 谢谢!它通过结合这两个语句来工作。击键(作为文本的项目的 POSIX 路径)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-31
    • 2018-09-29
    • 1970-01-01
    相关资源
    最近更新 更多