Hello

Brad Dominy


iChat Stock Ticker

A fun little script that puts a scrolling stock ticker in your iChat status.


Copy and paste into AppleScript Editor if you want to try it out.

set stockList to {"^DJI", "^IXIC", "AAPL", "AKAM", "TIVO", "SIRI", "AIG", "MSFT", "STEC", "F", "ESLR", "GME", "UAUA", "BAC", "WFC"}
set upCh to "▲"
set dnCh to "▼"

repeat
set m to ""
repeat with daSymbol in stockList

    -- fetch quote page
    set q to do shell script "curl \"http://www.google.com/finance/info?client=ig&q=" & daSymbol & "\" -o /tmp/temp.html ; cat /tmp/temp.html"

    set pq to parse_quote(q)

    set m to m & _t of pq & " " & _l_cur of pq & " "
    set c to _c of pq as number

    if c < 0 then
        set m to m & dnCh
    else if c > 0 then
        set m to m & upCh
    else
        set m to m & "-"
    end if
    set m to m & " " & c & " ( " & _cp of pq & "% )       "
end repeat

set i to 0
set l to length of m

tell application "iChat" --to 
    repeat
        set i to i + 1

        set n to text i thru -1 of m

        if i > 1 then set n to n & text 1 thru (i - 1) of m

        if i ≥ l then
            set i to 0
            exit repeat
        end if

        set the status message to n
        delay 0.1
    end repeat
end tell
end repeat

on parse_quote(q)

set r to {} as record

set li to get every paragraph of q
repeat with thisLine in li

    set o1 to offset of ":" in thisLine

    if o1 > 0 then
        --log clean(thisLine)

        set k to clean(text 1 thru (o1 - 1) of thisLine)
        set v to clean(text (o1 + 1) thru -1 of thisLine)

        if k is "id" then
            set r to r & {_id:v}
        else if k is "t" then
            set r to r & {_t:v}
        else if k is "e" then
            set r to r & {_e:v}
        else if k is "l" then
            set r to r & {_l:v}
        else if k is "l_cur" then
            set r to r & {_l_cur:v}
        else if k is "ltt" then
            set r to r & {_ltt:v}
        else if k is "lt" then
            set r to r & {_lt:v}
        else if k is "c" then
            set r to r & {_c:v}
        else if k is "cp" then
            set r to r & {_cp:v}
        else if k is "ccol" then
            set r to r & {_ccol:v}
        end if
    end if

end repeat
return r
end parse_quote

on clean(t)

set out to ""

if length of t > 0 then
    repeat with i from 1 to length of t
        set ch to character i of t
        if ch is "\"" then

        else
            set out to out & ch
        end if
    end repeat
end if

if character 1 of out is "," then set out to text 2 thru -1 of out

return trim(out)
end clean

on trim(someText)

if length of someText > 1 then
    repeat until someText does not start with " "
        set someText to text 2 thru -1 of someText
    end repeat

    repeat until someText does not end with " "
        set someText to text 1 thru -2 of someText
    end repeat
end if
return someText
end trim

About me

Brad Dominy

Projects

By Language

By Frameworks