6 Replies Latest reply: Apr 8, 2012 5:09 AM by Reelin123
jrdrumbum3896 Level 1 Level 1 (5 points)

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)
  • 1. Re: Find text in webpage and email notification applescript/automator
    twtwtw Level 5 Level 5 (4,690 points)

    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

                                   make new to recipient at end of to recipients with 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.

  • 2. Re: Find text in webpage and email notification applescript/automator
    jrdrumbum3896 Level 1 Level 1 (5 points)

    that worked great, the only thing is everytime I open the application, it says "can't set document 1 of window 1 of application "safari" to "website". But if I click OK it starts working.

  • 3. Re: Find text in webpage and email notification applescript/automator
    jrdrumbum3896 Level 1 Level 1 (5 points)

    I fixed that so nevermind. But what would I set the time to for a delay of 1 hour instead of 15 minutes?

  • 4. Re: Find text in webpage and email notification applescript/automator
    twtwtw Level 5 Level 5 (4,690 points)

    for 15 mintes use return 900 in the idle loop. for an hour use return 3600.  Just use the appropriate number of seconds.

  • 5. Re: Find text in webpage and email notification applescript/automator
    jrdrumbum3896 Level 1 Level 1 (5 points)

    thank you very much!!!!!!! You're a life saver

  • 6. Re: Find text in webpage and email notification applescript/automator
    Reelin123 Level 1 Level 1 (0 points)

    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