Applescript is my enemy

One of the things I need to do for the current project with Arcane Wonders is to take a large amount of Excel data and turn it into HTML.

In the past I would have done this sort of thing in Director and built a quick Lingo function to read in some CSV data and then spit out the HTML. For years I did this sort of thing and it was the main reason why, despite not using it for any projects, that Director stayed on my hard-drive. Whatever one might think of Director, Lingo is actually a wonderfully adept language that is easy to use.

I no longer have any copies of Director. Or at least ones that will work on my current Mac. And so recently I have been using Applescript to take data from Numbers and manipulate it. I did it for the Catalyst Game Labs project to take data from their old online store and reformat it into a set of SQL inserts. And I am doing it for Arcane Wonders to turn data about the cards for their Mage Wars game into HTML data.

Sadly Applescript is a nightmare. Or at least I think it is. I ran into several issues in my code this evening where, since I have been writing in Javascript for a week, I forgot to add the “set” keyword to the beginning of a few lines and inadvertently set up a few conditional tests between variables and values.

Nothing major but what was frustrating is that Applescript seemed to think that a referenced string value in a list was not the same as the string variable with the same data. I am not sure how that makes any sense but I had to change

repeat with aType in cardTypeList
	set currentCard to currentCard + 1
	if (aType is equal to largeCardName) then
		return item currentCard of smallCardNames
	end if
end repeat

to

repeat with aType in cardTypeList
	set currentCard to currentCard + 1
	if (item currentCard of cardTypeList  is equal to largeCardName) then
		return item currentCard of smallCardNames
	end if
end repeat

Despite the fact that, in the code, aType should be the same as item currentCard of cardTypeList Applescript was not evaluating them as being equal.

Applescript, while handy, is full of things like this that are frustrating as hell.

Maybe I should learn Python?

Sadly though Python doesn’t have the direct access to the OS and applications that Applescript does.

Advertisements
Tagged , ,