Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Using automator, I have navigated to a website that required a password, pulled up a page and need to search that page for a word. Let's say the word is "flowmaster" for example. I had Automator do a 'watch me do' and typed Cmd-F to search that page. I type in flowmaster and it returns in the spotlight command line 0 matches.

Let's say I want it to keep re-searching the page and when the word 'flowmaster' comes up as a match, have it send an email to me to alert me that it is on the page. When I have Automator 'get text from webpage' or 'get contents of webpages' it just returns the title of the page or the opening page of the website.

To show you what I am trying to do, type "command F" now, then type in "flowmaster" it should say to the left of the spotlight search 4 matches and the left/right arrow keys. That is the data I am looking for. Is there a way to have that 1 match information trigger an event? Like, if there is 1 match, send email saying "one available". The problem with the 'watch me do' is that there is nothing there for most of the time, but when the word pops up on the website, I need it to alert me.

Is this possible?

share|improve this question
add comment

1 Answer 1

Automator's "Watch Me Do" functionality is pretty limited, as you've discovered. Additionally, imitating how a user might go about something isn't always the best way to automate things — for example, the computer doesn't need to open up a browser window and use the find panel to search the text of a webpage, it can just download the data and search it without need for any of the GUI niceties.

Automator Email Notifications for Matching Text on a Site

  1. Add a Get Specified URLs action. Add to it the address of the page you want to check.
  2. Add a Get Text from Webpage action and make sure the dropdown is set to plain text.
  3. Add a Run Shell Script action, with the shell set to /bin/bash and the input setting to to stdin. Enter the following text, replacing search term with the text you want to match (be sure to keep the quotes if the string has spaces):

    grep -o "search term" | wc -l | tr -d " "
    

    Note that the search is case sensitive.

  4. Add a Run AppleScript action, and insert the following text, replacing me@example.com as appropriate:

    on run {input, parameters}
        if input > 0 then
            tell application "Mail"
                set theNewMessage to make new outgoing message with properties {subject:"Found Matches", content:"Found " & input & " matches", visible:false}
                tell theNewMessage
                    make new to recipient at end of to recipients with properties {address:"me@example.com"}
                    send
                end tell
            end tell
        end if
    end run
    

    You can replace the subject and content, but be sure to properly format them as AppleScript strings (I'll leave this as an exercise to the reader, it's fairly easy to figure out, Google if necessary).

That will send an email if there are any matches for the string on the site. The AppleScript is used instead of Automator's email actions because Automator doesn't offer any conditional (i.e. if statements) means of performing actions, and we only want to send an email if a match was found. Let me know in the comments if you have any questions.

share|improve this answer
    
Rob, thanks for answering, sorry I have been out for a bit. I tried the automator actions you suggested. Just a couple of questions, (please forgive my LINUX ignorance, I would never have figured out the grep phrase).I just bought applescript:missing manual to learn, and my attempt with automator is using a hammer to turn a nut. I ran the workflow, however, the page I am looking to search is actually in a frame and the get text from webpage did not return any search results. I had brute forced an imacro using 'watch me do' to return results, but can't get that to return a result either. –  John S Dec 12 '12 at 1:05
    
I had tried using imacros to navigate to the page (after logging in with name and password--which I can brute force with 'watch me do'), however, the page has several submenu selections such as date and menus that I navigate to, then look to see if the key word is there. I believe the site is in javascript and the imacros would extract the phrase by selecting the frame and searching for the keyword in that frame. Using get text from webpage only returned a couple of menu headers, but not the text I was looking for. Thanks, John S –  John S Dec 12 '12 at 1:14
    
Getting content from a dynamically generated site can be tricky, if that content isn't reliably available from a specific URL (e.g. how a Google search can be constructed via URL parameters). It's doable, but it's really beyond the scope of Automator or AppleScript. I typically use Python for something like that. However it may be just the frames stymieing you, in which case, right click in the frame with the content you want, and click Open Frame in New Tab, and copy the frame's URL from there into the Get Text from Webpage action. –  robmathers Dec 12 '12 at 2:32
    
Hey Rob, thanks again for your input and patience. I managed to partially run your ideas. By right clicking the frame, I saved it as a html file as the page source. I used finder in automator to process the file using your grep phrase to search the source for the keyword and from that, the rest of your code worked like a champ emailing me. (golf clap) My solution is a bit heavy handed, however, as I used watch me do to navigate to the site, select the frame, right click and save the file, then select override file...I'm sure there is a way to command that, however this works, to a point... –  John S Dec 14 '12 at 3:42
    
Alright Rob, update, you are correct, the frames are tricky and even getting Automator to right click proved to be tough. I had 'watch me do' record the right click on the page, then finished up with some applescript to keystroke "s" to save the page, then analyze it using your shell. Later, I discovered that when I changed to another frame on that page, it would not copy the new info, so I changed tactic. I found that selecting the new frame, then command-a and command-c got EVERYTHING, including the new info, to the clipboard. I ran your shell to analyze the clipboard and it works great! –  John S Dec 20 '12 at 22:20
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.