Okay, good news it it works partially after renaming all the table names appropriately. However, after the first document is done copying to the master, it keeps creating infinite rows in the first table before it starts copying from the next document. Thoughts?
script o
# These properties will be visible from the handler but will not be saved on disk
property peopleNames : {}
property targetName : missing value
end script
set path2Target to choose file with prompt "Please select today's Master:" of type {"com.apple.iwork.numbers.numbers", "com.apple.iwork.numbers.sffnumbers"} # Edit to fit your needs
set folder4peoples to (path to desktop as text) & "Daily Sheets" # Edit to fit you needs
tell application "Finder"
set peopleFiles to every file of folder folder4peoples as alias list
end tell
# Now we have a list of the available people files
# The main document is supposed to be
tell application "Numbers"
open path2Target as «class furl»
set o's targetName to name of document 1
set o's peopleNames to {}
repeat with aPeopleFile in peopleFiles
set aPeopleDoc to open aPeopleFile
set end of o's peopleNames to name of aPeopleDoc
end repeat
end tell
# Now we have a list of the available people documents
# I'm not sure that the upper row to import is the same in every tables
# So I define several ones.
set upper1_1 to 2
set upper1_2 to 2
set upper1_6 to 2
set upper3_1 to 2
set upperInMain to 2
set rowsFilled to 0
repeat with aPeopleName in o's peopleNames # Edit sheets and tables names to fit your needs.
set rowsCnt to my importFrom(aPeopleName, "Watch List", "Watch List", {"B", "I", "K", "L", "M", "N"}, upper1_1, upperInMain, 0)
set rowsCnt to my importFrom(aPeopleName, "Watch List", "Scheduled Callbacks", {"A", "E", "F", "G", "H", "I", "J", "K", "L", "M"}, upper1_2, upperInMain, rowsCnt)
set rowsCnt to my importFrom(aPeopleName, "Watch List", "Voicemail Tracker", {"A", "D", "E"}, upper1_6, upperInMain, rowsCnt) # I deliberately missed the brackets
set rowsCnt to my importFrom(aPeopleName, "PASTE HERE", "PASTE HERE", {"A", "B", "C", "D", "E", "F"}, upper3_1, upperInMain, rowsCnt)
set rowsFilled to rowsFilled + rowsCnt
set upperInMain to upperInMain + rowsFilled
# So datas from the next people will be pasted starting from the same row in every table.
end repeat
display notification "The Master Has Been Merged!" with title "Thanks For Using Master Merger!" sound name "Glass.aiff"
on importFrom(aPeopleName, sheetName, tableName, theColumns, higherRowInPeople, higherRowInTarget, maxnumber)
# Take care of possible omission of brackets when there is a single column to treat
if class of theColumns is not list then set theColumns to {theColumns}
set windowMenu to 11 # Index of the menu "Window"
copy higherRowInTarget to upperRow
tell application "Numbers"
repeat with c from 1 to count theColumns
set aColumn to (item c of theColumns) as text
tell document aPeopleName
tell sheet sheetName to tell table tableName
tell column aColumn
repeat with i from (count rows) to 1 by -1
if value of cell i is not missing value then exit repeat
end repeat
set theRange to (name of cell higherRowInPeople) & ":" & (name of cell i)
end tell
set maybe to i - higherRowInPeople + 1
if (maybe > maxnumber) then set maxnumber to maybe
set selection range to range theRange
end tell # sheet.
end tell # document
tell application "System Events" to tell process "Numbers"
set frontmost to true
tell menu bar 1 to tell menu bar item windowMenu to tell menu 1 to click menu item aPeopleName # brings the people window to front
keystroke "c" using {command down}
end tell
# the clipboard contains the datas from the people
tell document (o's targetName) to tell sheet sheetName to tell table tableName
if (upperRow > (count rows)) then
repeat (upperRow - (count rows)) times
add row below last row
end repeat
end if
set selection range to range (name of cell upperRow of column aColumn)
end tell
tell application "System Events" to tell process "Numbers"
tell menu bar 1 to tell menu bar item windowMenu to tell menu 1 to click menu item (o's targetName) # brings the main window to front
keystroke "v" using {command down}
end tell
end repeat
return maxnumber
end tell # Numbers
end importFrom