代码之家  ›  专栏  ›  技术社区  ›  Ankonian

Applescript击键Filepath变量

  •  0
  • Ankonian  · 技术社区  · 9 年前

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

    末端运行

    1 回复  |  直到 9 年前
        1
  •  0
  •   vadian    9 年前

    这取决于 input / theItem 。击键必须为 text , input 可以是任何东西。

    尝试

    keystroke (theItem as text)
    

    keystroke (POSIX path of theItem)
    

    System Events 相当于 §G

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