Using AppleScript with Numbers to synchronize two open documents
I have two Numbers documents used for a fantasy sports draft. Both documents need to be open on the same MacBook during the draft but one document will always be the active window for the operator and the other document will run in a passive window in a separate desktop and be projected to an external display for the rest of the draft participants to see.
The active document Draft is used to enter players selected by each fantasy owner. The primary input cell is a search field in a row which will trigger a lookup in a players database and return a unique ID# along with additional player information such as position and team.
The passive document Board is simply a matrix display of the draft progress. It uses the same background data as Draft to fill the contents of the draft board.
This fantasy draft usually takes 32 rounds (only 12 shown here) and is a session lasting several hours with hundreds of rows of data.
It is known this operation can be done by using separate devices, such as an iPad to enter the draft picks and the MacBook to display the draft board, and letting them synchronize using iCloud. However, this requires a reliable network connection (not always available) and results in a delay of 15-30 seconds between data entry and board update which is unacceptable.
The objective is as each row is completed in the Draft document, to send the value of the selected player's ID# to the Board document. So this as simple as piping the value of a single cell from one document to another.
Both documents share several identical tables, such as the list of Owners and a Players database. But most importantly, they each have a Picks table which will have the exact same dimensions, i.e. number of columns and rows. Consequently, the cell to synchronize will have the exact same address in the Picks table in both documents.
I’m trying to use AppleScript. However, I have no experience with it so am struggling with several I'm sure basic issues, most notably how to operate with two open Numbers documents at once.
Here is a view of the primary windows of each of the two documents, Draft and Board.
In Draft, the first row has already been entered, by typing the string "yama" into the search field (E52). The LOOKUP formula in cell F52 concatenates the search string with "*" to enable a wild card lookup in the Players database and returns that players ID# along with additional information.
The results are displayed in Row 3, which is in the frozen table header to allow scrolling of the entry rows below. Row 3 shows the Owner, Round, and ID#, Name, Position and Team of the selected Player. Also in this row are two key fields for controlling the script - the Cell column contains the address of the cell (ID#) in the Picks table to be sent from Draft to Board, and the Status column indicates whether or not this ID# has been sent (by the script).
So in this instance, the operator entered "yama" for Owner = Lincoln in the search field, which filled the rest of the row with ID# = 1183, Player = YAMAMOTO,Yoshinobu, Pos = P, and Tm = LAD. The cell to be synchronized is at the address F52, which contains the value 1183. The idea is when the script executes and sends the value at F52 from Draft to Board, it then sets the semaphore (Status) to TRUE.
Meanwhile, the new active row becomes Row 55, its Status is initialized to FALSE, and once entered will reset the contents of Row 3 with owner Jefferson's pick, and so on.
Here is my attempt using AppleScript, opening only one Numbers document. But I am stuck.
MacBook Pro (2017 – 2020)