Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Find text in webpage and email notification applescript/automator

Hey guys, I'm trying to make (what I think is) a fairly complicated automator/applescript action. Basically, I'm trying to buy a certain product and it is only available on the webpage at certain times. So I want to create a function that will constantly run in the background on my computer. I want this function to reload a safari page every 10-15 minutes (the one with the store's product page), search for text (the name of the product) and either stop there if the text isn't found or if the text is found, open mail and send myself an email notification so that I'll get it on my phone if the product becomes available. Is this possible at all?

Mac mini, Mac OS X (10.5.8)

Posted on Jun 16, 2011 10:37 AM

Reply
Question marked as Best reply

Posted on Jun 16, 2011 12:54 PM

this might do what you're looking for:

on idle

set pagURL to "http://page.url.com?whatever"

if application "Safari" is not running then

quit

return

end if

tell application "Safari"

set URL of document 1 of window 1 to "http://your.web.address/"

delay 5


-- delay to let page load.


-- there are more elegant ways of doing this using do javascript, but this will suffice.

if source of document 1 of window 1 contains "search text" then

my sendAMail()

end if

return 900 --fifteen minutes

end tell

end idle


on sendAMail()

tell application "Mail"

set theMess to make new outgoing message at end with properties {sender:"your name", subject:"some subject line", content:"The message you want to send to yourself", visible:true}

tell theMess

makenewto recipientat end of to recipientswith properties {address:"email@adress.com"}

end tell


-- send theMess

end tell

end sendAMail

copy it into the applescript editor, edit in all the correct information about the web page, your email address, etc., then save it as a stay open application. when run, it will periodically reload and check the page - adjust the number after the return statement to set it to different time periods.


test it first, then when you're ready to use it set visible:false in the line where you make the message, and uncomment the send theMess line. this will get mail to make and send the message invisibly.

6 replies
Question marked as Best reply

Jun 16, 2011 12:54 PM in response to jrdrumbum3896

this might do what you're looking for:

on idle

set pagURL to "http://page.url.com?whatever"

if application "Safari" is not running then

quit

return

end if

tell application "Safari"

set URL of document 1 of window 1 to "http://your.web.address/"

delay 5


-- delay to let page load.


-- there are more elegant ways of doing this using do javascript, but this will suffice.

if source of document 1 of window 1 contains "search text" then

my sendAMail()

end if

return 900 --fifteen minutes

end tell

end idle


on sendAMail()

tell application "Mail"

set theMess to make new outgoing message at end with properties {sender:"your name", subject:"some subject line", content:"The message you want to send to yourself", visible:true}

tell theMess

makenewto recipientat end of to recipientswith properties {address:"email@adress.com"}

end tell


-- send theMess

end tell

end sendAMail

copy it into the applescript editor, edit in all the correct information about the web page, your email address, etc., then save it as a stay open application. when run, it will periodically reload and check the page - adjust the number after the return statement to set it to different time periods.


test it first, then when you're ready to use it set visible:false in the line where you make the message, and uncomment the send theMess line. this will get mail to make and send the message invisibly.

Apr 8, 2012 5:09 AM in response to twtwtw

Hi, I have a similar problem. Next week a new limited edition product will be available. When it comes out some redemption codes will be posted on the site. I already have an auto refresh extension on safari but i would like a script to autmatically copy the code as soon as it is posted. it will contain numbers, letters and - .


Thanks

Find text in webpage and email notification applescript/automator

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.