Monday, February 08, 2010


I've been doing some grading for a course and I wanted to automate somewhat sending feedback to the students. I am able to get a CSV file with the roster information and their submissions follow a particular format (Lastname_Firstname_...). So when I'm done grading and commenting, I want to be able to blast out the comments in emails. There are about 50 students in the course so sending an email to each one would take a long time.
Here is the first script:

C_DIR=$( pwd )
cd $HW_DIR
for file in *; do
LAST_NAME=$( echo $file | cut -d _ -f1 )
FIRST_NAME=$( echo $file | cut -d _ -f2 )
while read line; do
RLAST_NAME=$( echo $line | cut -d "," -f2 | tr -d \" )
RFIRST_NAME=$( echo $line | cut -d "," -f3 | tr -d \" )
if [ "$LAST_NAME" == "$RLAST_NAME" -a "$FIRST_NAME" == "$RFIRST_NAME" ]; then
EMAIL=$(echo $line | cut -d , -f4 | tr -d \" )
$C_DIR/sendmail "$FIRST_NAME $LAST_NAME" $EMAIL "$SUBJECT" "Results: " $C_DIR/$HW_DIR/$file
done < $C_DIR/$ROSTER
if [ $FOUND -eq 0 ]; then
echo "Oh NO!"
echo $file

It takes as input the directory with the files I want to send and a subject line for the email.

And here is my sendmail script:

on run argv
set _name to (item 1 of argv)
set _to to (item 2 of argv)
set _subject to (item 3 of argv)
set _body to (item 4 of argv)
set _attachment to (item 5 of argv)
tell application "Mail"
set theMessage to make new outgoing message with properties {visible:true, subject:_subject, content:_body}
tell theMessage
make new to recipient at end of to recipients with properties {name:_name, address:_to}
end tell
tell content of theMessage
make new attachment with properties {file name:_attachment} at after last paragraph
end tell
send theMessage
end tell
end run

No comments: