Hi Jonathan,
Does the following work for you better. Edit the properties to fit your setup. As written it assumes one Header Row, no blanks in the list of symbols, and no Footer Row.
The table will expand automatically to accommodate the columns and rows in your data. It won't shrink automatically, however. So if you reduce the number of data items you are retrieving you simply delete extra columns and run.
Will be interested in hearing how it works on your end.
SG
--retrieves stock quotes and other data from Yahoo! and places in Numbers table
--Usage: place symbols in column starting at row 2; no blanks; no footer row
--Change properties to fit your setup
--https://discussions.apple.com/thread/5822522?answerId=25127300022#25127300022
property quote_properties : "l1r0e7e8s6"
-- see https://code.google.com/p/yahoo-finance-managed/wiki/enumQuoteProperty
--p0 prev close; l1 last trade; e7 est EPS curr yr; e8 est EPS next yr; s6 revenue
--p6 p/b; r0 pe; y0 div yield, j4 EBITDA,j2 shares out; n0 name;s0 symbol, etc
property target_sheet : "Sheet 9"
property target_table : "Table 1"
property symbol_column : 1
property data_start_cell : "B2"
tell application "Numbers" to tell front document to tell sheet target_sheet to tell table target_table
tell column symbol_column to set symbols to my joinList(value of cells 2 through (count of cells), "+")
set paste_str to my csv2tsv(my getYData(symbols, quote_properties))
set the clipboard topaste_str
try
set the selection range to cell data_start_cell
on error
display alert "You designated a cell that doesn't exist. Check your table." buttons "OK"
return
end try
tell application "Numbers" to activate
tell application "System Events" to keystroke "v" using {option down, shift down, command down}
display notification "Stock data has been updated" with title "Numbers"
end tell
to getYData(symb, q_prop) -- get Yahoo! data
try
set base_url to "http://download.finance.yahoo.com/d/quotes.csv?"
set symb_str to "s=" & symb
set property_str to "&f=" & q_prop
set script_str to "curl -s " & "'" & base_url & symb_str & property_str & "'"
set r to do shell script "curl -s " & script_str
if r's text items 1 thru 2 as text is equal to "<!" then error
return r
on error
display alert "Had trouble getting data from Yahoo! server. Check symbols! No blanks."
end try
end getYData
to joinList(a_list, list_delimiter) --convert AS list to delimited string
set orig_tid to text item delimiters of AppleScript
set text item delimiters of AppleScript to list_delimiter
set r to a_list as string
set text item delimiters of AppleScript to orig_tid
return r
end joinList
to csv2tsv(str) -- Numbers 3 wants tsv for pasting
set orig_tid to text item delimiters of AppleScript
set text item delimiters of AppleScript to ","
set l to text items of str
set text item delimiters of AppleScript to tab
set str to l as text
set text item delimiters of AppleScript to orig_tid
return str
end csv2tsv
--end of script