I am trying to create a script that will upload products for me using Applescript and Automator. Im getting an error when the script tries to use the variable for the file path as it iterates through my list. The code is below. I am also inputing the contents of a folder from automator into this script. The error is on line 22. Also, if you could help with the second keystroke on line 42 which needs to iterate with the repeat but in a different folder. Thanks in advance!
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
end run
It depends on the class of input / theItem
. Keystrokes must be text
, input
can be anything.
Try
keystroke (theItem as text)
or
keystroke (POSIX path of theItem)
And in System Events
the equivalent of ⇧⌘G is
keystroke "g" using {command down, shift down}