Automator: Using Cmd F in a "watch me do" and trying to make decisions based on the results

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?


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 [email protected] 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:"[email protected]"}
                    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.