Greetings,
I am still working through the AppleScript 1-2-3 Book, and I have probably bit off more that I can chew in what I am trying to do.
Here is the situation, I have a class list which is a Numbers file. I have an assortment of Project Rubrics also set up as custom templates in Numbers.
I’d like to generate a folder of blank rubrics - one for each student, each rubric will be named “Lastname_firstname.numbers” for example Smith_Joe.numbers. I also want that same name pasted into the “student name” cell of the rubric.
This way when it’s time to grade the projects, I have a blank project rubric for each student with their name already inserted all ready to go.
I have a script that generates a list of student names based on a selected class list table.
I have a script that has numbers give me a dialogue to pick a rubric template.
The wheels fell off when I tried to put them together and do more.
I provided a download link to sample class list and a sample custom rubric template, and a couple of scripts that I was working on.
https://dl.dropboxusercontent.com/u/9734532/My%20Sharing/Sample_Source_Files.zip
I generally have about 100 students per term with 3 or 4 projects so if I am able to get something working it would be a massive time-saver for me.
Any assistance would be greatly appreciated!
Thanks in advance!
Bill
(*
http://macscripter.net/viewtopic.php?id=45693
Create students Rubrics
*)
set thisTemplateName to my defineTheTemplate()
# Edit the pathToList to fit your needs
set pathToList to (path to downloads folder as text) & "Sample_Source_Files:Sample_Class_List.numbers"
# Edit the storageName and p2d to fit your needs
set storageName to "the Rubrics"
set p2d to path to desktop folder as text
set storageFolder to p2d & storageName & ":" # don't remove the ending colon
tell application "System Events"
if not (exists folder storageFolder) then
make new folder at end of folder p2d with properties {name:storageName}
end if
end tell
tell application "Numbers"
open pathToList as «class furl»
try
if not (exists document 1) then error number 1000
tell document 1 to tell sheet 1 to tell table 1
set studentNames to {}
repeat with i from 2 to count rows
tell row i
if value of cell 1 is not in {missing value, "", " "} then
set end of studentNames to value of cell 4 & "_" & value of cell 5
end if
end tell
end repeat
end tell # document
close document 1 # Sample_Class_List.numbers is no longer useful
on error errorMessage number errorNumber
if errorNumber is 1000 then
set alertString to "MISSING RESOURCE"
set errorMessage to "You must create a list of students before running this script."
else
set alertString to "EXECUTION ERROR"
end if
display alert alertString message errorMessage buttons {"Cancel"}
error number -128
end try
# Now we have a list of students
repeat with anID in studentNames
make new document with properties ¬
{document template:template thisTemplateName}
try
if not (exists document 1) then error number 1010
set theSpreadsheet to (storageFolder & anID & ".numbers") as «class furl»
tell document 1
tell sheet 1
tell table 1
set value of cell 2 of row 1 to anID as text
end tell # table
end tell # sheet
end tell # document
save document 1 in theSpreadsheet
close document 1
on error errorMessage number errorNumber
if errorNumber is 1010 then
set alertString to "MISSING RESOURCE"
set errorMessage to "Please create or open a document before running this script."
else
set alertString to "EXECUTION ERROR"
end if
display alert alertString message errorMessage buttons {"Cancel"}
error number -128
end try
end repeat
end tell # Numbers
#=====
on defineTheTemplate()
tell application "Numbers"
activate
try
-- get User template names
set templateNames to ¬
the name of every template whose id of it begins with "User/"
-- prompt user to pick a template
set thisTemplateName to ¬
(choose from list templateNames with prompt "Choose a rubric template:")
if thisTemplateName is false then error number -128
-- extract the string from the list: {"Black"} to "Black"
set thisTemplateName to (thisTemplateName's item 1)
return thisTemplateName
on error errorMessage number errorNumber
if errorNumber is not -128 then
display alert "TEMPLATE ISSUE" message errorMessage buttons {"Cancel"}
error number -128 # to exit after clicking OK in the alert
end if
end try
end tell
end defineTheTemplate
#=====
Yvan KOENIG running Sierra 10.12.4 in French (VALLAURIS, France) mercredi 3 mai 2017 20:12:26
Thank you for the feedback.
Yvan KOENIG running Sierra 10.12.4 in French (VALLAURIS, France) jeudi 4 mai 2017 10:41:14