I’m having trouble getting a script to run in Numbers. The script is designed to add rows to a spreadsheet and populate each row after it’s been added. However, after about 10 rows have been added Numbers hangs and the AppleScript times out with a -1712 error.

Here is the code. The purpose of this script is to download a historical set of stock data using the STOCKH function in Numbers. I can post a sample data set and a target data set but it’s basically a stock symbol, date, price, high, low and volume row. The script adds historical data for each new stock symbol, working from the bottom of the table upwards.

Any help would be appreciated - Thanks!

```
tell application "Numbers"
activate
set daysToDownload to 10 -- number of total rows for each stock
tell document 1
tell active sheet
set the selectedTable to (the first table whose class of selection range is range) --need to select at least 1 cell in the target spreadsheet
end tell
--display dialog "How many days do you want to download?" default answer ""
--set daysToDownload to text returned of result
--display dialog daysToDownload
tell selectedTable
-- store the row to copy as the reference row of the table; we pick the last row assuming that each row is a unique stock symbol
set startingRow to last row's address of column 1
repeat until startingRow = 1
set rowTarget to startingRow
set rowToCopy to value of cells of row rowTarget -- values for this row
repeat with j from 2 to daysToDownload --create a row copy with a new historical date (working backwards throught the calendar)
set x to properties of row rowTarget
set r to make new row at after row rowTarget with properties x -- add in a blank row below rowTarget
set value of cell 1 of row (rowTarget + 1) to item 1 of rowToCopy --fill in the blank row with the ticker symbol (item 1) from rowToCopy; Applescript seems to copy the formulas from columns C, D, E, and F even though it's not asked to copy them
--get the location of the date cell and add a formula to subtrack one workday from the prior row; assumes date is in column B
set value of cell 2 of row (rowTarget + 1) to "=WORKDAY(" & "B" & rowTarget & ",-1)"
set rowTarget to rowTarget + 1 -- add one row to the rowTarget and repeat the process
end repeat
set startingRow to startingRow - 1
end repeat
end tell
end tell
end tell
```

Model: iMac 13,2

AppleScript: 2.7

Browser: Safari 605.1.15

Operating System: Mac OS X (10.13 Developer Beta 3)