I am trying to write a macro that helps me enter grades for students into LaTeX. Right now I enter the grades via a complicated cut and paste from an Excel spreadsheet, but I'm hoping an Applescript macros can make it easy to enter them into LaTeX directly. The problem is, I really just discovered Applescript and I'm not even sure if what I want to do is possible. What I want is something like this macro:
Code: Select all
--Applescriptproperty texapp : "TeXShop"tell application texappset the setgrade to "\\setgrade{student}{"set q1 to display dialog "Student Name" & return & "Quiz 1" default answer "0"set grade1 to the text returned of q1set the grade1 to setgrade & "1}{" & grade1 & "}" & returnset q2 to display dialog "Student Name" & return & "Quiz 2" default answer "0"set grade2 to the text returned of q2set the grade2 to setgrade & "2}{" & grade2 & "}" & returnset the gradetext to grade1 & grade2tell application "TeXShop" to set the content of the selection of the front document to gradetextend tell
Code: Select all
Code, edit and compile here:
\documentclass[12pt]{article}\usepackage{etoolbox}\newcommand{\setgrade}[3]{\csedef{#1-grade-#2}{#3}}\setgrade{student}{1}{70}\setgrade{student}{2}{88}\begin{document}\begin{tabular}{ l | c | c|}& 1 & 2 \\ \hline Student & \csuse{student-grade-1}& \csuse{student-grade-2}\\ \hline\end{tabular}\end{document}
Here's the catch: what I really need is a way for the Applescript dialogs to ask only for grades that have not yet been entered. So once the grade for Quiz 1 is entered, I don't want the script to ask for it when I run the macro again. If this were just straight LaTeX, I would just use something like \ifcsdef{student-grade-1}{... , but I presume its not possible to mix a command like that in with the Applescript.
Is there a way to do this with an Applescript macro? Is it possible to do this at all? If I'm barking up the wrong tree and there's a much simpler way to approach this problem, feel free to point me in a different direction. I'm not a programmer and fiddle around with this stuff largely in a vacuum, so I never know when I'm trying to do something the crazy way!