--define file path: set downloadsFolder to path to downloads folder from user domain set absenceFile to (downloadsFolder as string) & "absences.numbers" --check existence of file: try absenceFile as alias on error number errorNumber if errorNumber = -1700 then display dialog "No absences file in Downloads folder!" buttons {"OK"} default button 1 with title "Missing file" with icon caution return --go no further end if end try tell application "Finder" to open absenceFile --build the date string: repeat with nextDate from 0 to 3 set today to (current date) + (nextDate * days) set theDay to day of today as string set theDayName to weekday of today as string set theMonth to month of today as string set theYear to year of today as string set dateString to theDayName & ", " & theDay & " " & theMonth & " " & theYear as text tell application "Numbers" delay 1 -- to allow file to open, may need adjusting activate tell document 1 tell sheet "Total absences" tell table "Names" set rowCount to count rows set allNames to value of cells of column 1 end tell end tell --get the absences for today: set absentNames to (choose from list allNames with prompt "It's " & dateString & "." & return & "Who is absent?" with multiple selections allowed) if the result is false then return --user cancelled --create today's sheet: set juanSheet to (make new sheet at beginning of sheets with properties {name:dateString}) set active sheet to juanSheet tell juanSheet --restructure default table: tell table 1 set name to "Absence record" set column count to 2 set row count to rowCount set {header row count, header column count} to {0, 0} set format of every cell of column 2 to checkbox --false by default --compare each row of table with list of absentees: repeat with x from 1 to rowCount set nextName to item x of allNames tell column 1 tell row x tell cell 1 to set value to nextName tell cell 2 if nextName is in absentNames then set value to true end tell --cell 2 end tell --row x end tell --column 1 end repeat end tell --table 1 end tell --juan sheet --add absences to running total on main sheet: tell sheet "Total absences" tell table 1 repeat with eachRow in rows tell eachRow set lastCount to value of cell 2 if lastCount is missing value then set value of cell 2 to 0 set lastCount to value of cell 2 end if if value of cell 1 is in absentNames then set value of cell 2 to (lastCount + 1) end tell --eachRow end repeat end tell --table 1 end tell --total absences sheet end tell --document 1 end tell --numbers end repeat