TeXShopA question about Applescript Macros

Information and discussion about TeXShop, an integrated LaTeX environment for Mac OS X
Post Reply
pvnotp
Posts: 4
Joined: Fri Apr 17, 2009 2:16 am

A question about Applescript Macros

Post by pvnotp »

Hello,

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

--Applescript 

property texapp : "TeXShop"
tell application texapp
	set 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 q1
	set the grade1 to setgrade & "1}{" & grade1 & "}" & return
	
	set q2 to display dialog "Student Name"  & return & "Quiz 2" default answer "0"
	set grade2 to the text returned of q2
	set the grade2 to setgrade & "2}{" & grade2 & "}" & return

	set the gradetext to grade1 & grade2

tell application "TeXShop" to set the content of the selection of the front document to gradetext
end tell
which can be used with this document

Code: Select all

\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}
to enter in grades and display them.


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!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

Re: A question about Applescript Macros

Post by josephwright »

I wonder if a better approach would be to save your Excel data as a plain text format (say CSV or tab separated) and to use pgfplotstable to read it in and build your table?
Joseph Wright
Post Reply