Q: Getting Stock Quotes in Numbers
Here is a very simple Apple script (thus somewhat constrained) derived from some very complicated French scripts posted here some time ago. Installation/usage instruction in the code below:
-----
(*
GetQuotes
AppleScript for Numbers - gets stock names from column 2 of row 2 to rowcount of the frontmost numbers' document, first sheet, first table, gets quotes for them from Yahoo and puts them in row 3.
To istall/use it:
- paste this text in AppleScript Editor, and save it as a script (any name) in your script folder (Library/Scripts)
- in Numbers open a document (single sheet, single table) containing stock symbols in the second column . To get the current quotes for them (placed in the third column) run the script from the Apple Script menu (this menu can be activated in AppleScript Editor preferences)
*)
property theApp : "Numbers"
--=====
on run
local texte, rowsCount, trueDoc, trueSheet, trueTable
say "starting"
set t3 to "http://" & "download.finance.yahoo.com/d/quotes.csv?s="
tell application "Numbers"
activate
set trueDoc to name of front document
set trueSheet to name of first sheet of document trueDoc
set trueTable to name of first table of sheet trueSheet of document trueDoc
tell application "Numbers" to tell document trueDoc to tell sheet trueSheet to tell table trueTable
set rowsCount to row count
end tell
end tell
repeat with y from 2 to rowsCount
tell application "Numbers" to tell document trueDoc to tell sheet trueSheet to tell table trueTable
tell row (y)
set parms to get value of cell (2)
end tell
set t4 to "&f=l1"
set request to t3 & parms & t4
end tell
set texte to download(request)
try
tell application "Safari" to close window 1
end try
tell application "Numbers" to tell document trueDoc to tell sheet trueSheet to tell table trueTable
tell row (y)
set value of cell (3) to texte
end tell
end tell
end repeat
beep 1
say "get quotes done"
end run
on download(t)
set t to do shell script "curl " & quoted form of t
return t
end download
-----
Here is a sample file you could use this script on.
Image: !http://img.skitch.com/20100722-eu1f5ixdh1k6axxmcntmceu6gm.jpg!
-----
(*
GetQuotes
AppleScript for Numbers - gets stock names from column 2 of row 2 to rowcount of the frontmost numbers' document, first sheet, first table, gets quotes for them from Yahoo and puts them in row 3.
To istall/use it:
- paste this text in AppleScript Editor, and save it as a script (any name) in your script folder (Library/Scripts)
- in Numbers open a document (single sheet, single table) containing stock symbols in the second column . To get the current quotes for them (placed in the third column) run the script from the Apple Script menu (this menu can be activated in AppleScript Editor preferences)
*)
property theApp : "Numbers"
--=====
on run
local texte, rowsCount, trueDoc, trueSheet, trueTable
say "starting"
set t3 to "http://" & "download.finance.yahoo.com/d/quotes.csv?s="
tell application "Numbers"
activate
set trueDoc to name of front document
set trueSheet to name of first sheet of document trueDoc
set trueTable to name of first table of sheet trueSheet of document trueDoc
tell application "Numbers" to tell document trueDoc to tell sheet trueSheet to tell table trueTable
set rowsCount to row count
end tell
end tell
repeat with y from 2 to rowsCount
tell application "Numbers" to tell document trueDoc to tell sheet trueSheet to tell table trueTable
tell row (y)
set parms to get value of cell (2)
end tell
set t4 to "&f=l1"
set request to t3 & parms & t4
end tell
set texte to download(request)
try
tell application "Safari" to close window 1
end try
tell application "Numbers" to tell document trueDoc to tell sheet trueSheet to tell table trueTable
tell row (y)
set value of cell (3) to texte
end tell
end tell
end repeat
beep 1
say "get quotes done"
end run
on download(t)
set t to do shell script "curl " & quoted form of t
return t
end download
-----
Here is a sample file you could use this script on.
Image: !http://img.skitch.com/20100722-eu1f5ixdh1k6axxmcntmceu6gm.jpg!
Mac OS X (10.4.7)
Posted on Jul 21, 2010 10:01 PM