Hello all. I just joined the forum and this is my first post. I’m new to Applescript so this may be an elementary question. I’m looking at a website that only stocks two certain products a few at a time and they sell out quickly. I am able to add the items to my shopping cart with quantity of zero, but when I change the quantity to one or more and then update the cart, the system automatically knocks the number down to whatever number is currently in stock (in most cases zero).
I’ve written an Applescript to do a rolling stock check, and it works great. It will tab down to the quantity fields, add 5 to each, and refresh the page. The problem is that this requires me to sit there and watch for the “number in cart” or “Subtotal” fields to change from zero to some other number. I’d prefer to make the script recognize if the “number in cart” field changes to anything other than “(0 item)”, at which point I’d like for it to stop or delay the script and give me a 3 beep alert.
The problem is that I can’t find a way to make it recognize a change to the “number in cart” field. Does anyone know of a way to do this? I can make a list of numbers that it would possibly change to (1 item-10 items), is there a way make it scan the web page for those phrases and then perform the action?
Here’s what I have written that works (I didn’t command it to open a page, this script assumes that the shopping cart is the active tab):
repeat
tell application "Safari"
activate
end tell
tell application "System Events"
tell process "Safari"
repeat 4 times
keystroke tab
end repeat
keystroke "5"
keystroke tab
keystroke "5"
keystroke tab
keystroke return
end tell
end tell
delay 30
end repeat
Here’s what I tried to write to recognize the change, but it doesn’t work. In this case it’s looking for the “number in cart” to change to “(1 item)”. If I could get it to work I’d add all of the possible numbers to the list. When I try to run it, it works fine until it gets to where I want it to look for the text “(1 item)” and it stops the script and gives me the error message “Can’t make source of document 1 of window 1 into type reference.”
repeat
tell application "Safari"
activate
end tell
tell application "System Events"
tell process "Safari"
repeat 4 times
keystroke tab
end repeat
keystroke "5"
keystroke tab
keystroke "5"
keystroke tab
keystroke return
end tell
end tell
delay 30
if source of document 1 of window 1 contains "1 item" then
beep 3
delay 60
else
delay 5
end if
end repeat
Any advice would be much appreciated. Thanks.
Model: MacBook Air, OSX 10.7.5
AppleScript: 2.4.3 (131.2)
Browser: Safari 537.73.11
Operating System: Mac OS X (10.7)