Get Bank Balance with Automator and AppleScript

Discussion in 'Mac Programming' started by sigamy, May 19, 2005.

  1. sigamy macrumors 65816

    Mar 7, 2003
    NJ USA
    One of my first ideas for Automator was to have it login to my online banking site, get my account balances and then speak the current balance out. Privacy isn't an issue in my house :D

    This would make my wife happy, she could just click one button and have the balances spoken out to her.

    After finding out about some of Automator's missing features (can't input into forms, Safari actions didn't want to download from pages with frames) I determined that I needed an AppleScript to do most of the work. I borrowed some code and now I have it all working, except for logging off of the online banking site. I'll work on that part tonight.

    My Workflow is:
    1. Call AppleScript that: goes to URL, inputs UserID & Password, clicks 'login' button, waits a few seconds, then copies all text in appropriate frame.
    2. TextEdit action to create a new document, paste text in from clipboard
    3. TextEdit action to search for "$" (there is a bunch of junk at beginning of file)
    4. System action for Text to Speech to have Vicki read my account balances.

    It's not perfect but it works.
  2. snkTab macrumors 6502a


    Nov 13, 2004
    Cincinnati, OH
    Just wait till your wife wants the computer to shop for her too. Then you are really in trouble. Make the computer tell your wife your balance is really half what it should be.
  3. swindmill macrumors 6502a


    Mar 17, 2005
    I'd like to create a workflow that does this, but I have no idea how to create the script needed. Where can I quickly (as possible) learn how to do this?
  4. wheezy macrumors 65816


    Apr 7, 2005
    Alpine, UT
    I like this, and I'm going to try this...but, Applescript, that's the problem. How do I write an Applescript to fill in the fields, and then press the login button?
  5. sigamy thread starter macrumors 65816

    Mar 7, 2003
    NJ USA

    Here is what I did. My online banking site uses forms so I had to do a bit of trial and error to find the correct form. You should be able to view the source of your bank's site to find out the function you need to call to mimic clicking the logon button.

    here is my workflow:

    1. Automator--Run Apple Script. Here is the script:

    on run {input, parameters}

    tell application "Safari"
    -- go to appropriate URL for your bank
    open location ""
    delay 3
    -- need to fill in the form with User ID and password
    do JavaScript "top.frames[1].document.forms[0].userId.value = \"" & "myUserID\"" in document 1
    do JavaScript "top.frames[1].document.forms[0].password.value = \"" & "myPass\"" in document 1
    delay 3

    -- now click the Login button, view source of bank page to see what function to call
    do JavaScript "top.frames[1].doStart()" in document 1
    delay 8

    activate -- not needed unless you want to watch
    -- grab all the text from the current web page
    set page_source to the text of front document
    end tell

    -- now tell TextEdit to paste the text
    tell application "TextEdit"
    activate -- not needed unless you want to watch
    set newDoc to make new document at end
    tell newDoc
    set paragraph 1 to page_source
    end tell
    end tell

    return input
    end run

    2. TextEdit -- Get Contents of TextEdit Document
    this just reads the text into memory

    3. TextEdit -- Filter Paragraphs
    When I log into my bank there is a bunch of "hi, how are you" text at the top of the page. I didn't want Vicki to read this text so I search for "$". She starts reading after the "$" and just yells out my current balance.

    4. System -- Speak Text

Share This Page