Greetings everyone!
I am new here so I’d first like to introduce myself. My name is Bill. I am a 54 year old College Professor from Canada who teaches Graphic Design. I am looking to learn AppleScript as a way to streamline my workflow. I am in no way a programmer and am in the very early stages of learning AppleScript. I am presently reading AppleScript 1-2-3 which is a big help.
There are a couple of tasks that I would really love to automate to speed up my grading so I can get back to the book.
The first one is I’d like to batch convert a folder of Numbers Files to PDF. (I set up my grading rubrics in Numbers, it works great!)
The second one is a bit more involved which is starting with a Numbers “Classlist” file, I want to automate creating a single Numbers file for each student based on a specific User Template for the current project (the rubric). The script would drop in the student’s name (Lastname first, then Firstname) into the “Name” cell" on the rubric, then save it as a Numbers file. i.e.) Smith_Steven.numbers . The goal is to create a unique Numbers file for each student so they are ready to go when I grade their projects. I like to set these all up ahead of time so I am ready when my grading workload gets extremely heavy. Presently, I am doing this task manually and it takes entirely too long.
I am really excited to learn AppleScript, but presently I am swamped with end-of-term grading. UGH. If I can automate these tasks it will help me out immensely.
Thanks in advance and I look forward to getting my AppleScript knowledge to the point where I can be a contributing member here in the forums!
I picked up the below code from iWork Automation website as a starting point for the exporting PDFs as a starting point but is not set up for Batch converting. Any help would be appreciated!
property exportFileExtension : “pdf”
property useEncryptionDefaultValue : true
– THE DESTINATION FOLDER
– (see the “path” to command in the Standard Additions dictionary for other locations, such as movies folder, pictures folder, desktop folder)
set the defaultDestinationFolder to (path to documents folder)
set usePDFEncryption to useEncryptionDefaultValue
tell application “Numbers”
activate
try
if not (exists document 1) then error number -128
if usePDFEncryption is true then
-- PROMPT FOR PASSWORD (OPTIONAL)
repeat
display dialog "Enter a password for the PDF file:" default answer ¬
"" buttons {"Cancel", "No Password", "OK"} ¬
default button 3 with hidden answer
copy the result to ¬
{button returned:buttonPressed, text returned:firstPassword}
if buttonPressed is "No Password" then
set usePDFEncryption to false
exit repeat
else
display dialog "Enter the password again:" default answer ¬
"" buttons {"Cancel", "No Password", "OK"} ¬
default button 3 with hidden answer
copy the result to ¬
{button returned:buttonPressed, text returned:secondPassword}
if buttonPressed is "No Password" then
set usePDFEncryption to false
exit repeat
else
if firstPassword is not secondPassword then
display dialog "Passwords do no match." buttons ¬
{"Cancel", "Try Again"} default button 2
else
set providedPassword to the firstPassword
set usePDFEncryption to true
exit repeat
end if
end if
end if
end repeat
end if
-- DERIVE NAME AND FILE PATH FOR NEW EXPORT FILE
set documentName to the name of the front document
if documentName ends with ".numbers" then ¬
set documentName to text 1 thru -9 of documentName
tell application "Finder"
set exportItemFileName to documentName & "." & exportFileExtension
set incrementIndex to 1
repeat until not (exists document file exportItemFileName of defaultDestinationFolder)
set exportItemFileName to ¬
documentName & "-" & (incrementIndex as string) & "." & exportFileExtension
set incrementIndex to incrementIndex + 1
end repeat
end tell
set the targetFileHFSPath to (defaultDestinationFolder as string) & exportItemFileName
-- EXPORT THE DOCUMENT
with timeout of 1200 seconds
if usePDFEncryption is true then
export front document to file targetFileHFSPath ¬
as PDF with properties {password:providedPassword}
else
export front document to file targetFileHFSPath as PDF
end if
end timeout
on error errorMessage number errorNumber
if errorNumber is not -128 then
display alert "EXPORT PROBLEM" message errorMessage
end if
error number -128
end try
end tell
– SHOW THE NEW PDF FILE
tell application “Finder”
activate
reveal document file targetFileHFSPath
end tell
Model: Late 2013 iMac with Fusion Drive
AppleScript: 2.9
Browser: Safari 603.1.30
Operating System: Mac OS X (10.10)