Greetings,
I’m relatively new to AppleScript. I’ve puttered about with some easy scripts, but now I’d like to try something a little more advanced. The problem is, I’m getting my butt kicked and I don’t know why.
I have a rather large HTML source page (from an online, browser- based game) in a Tex- Edit Plus 4.9.7 document (running on OS X.3.9) that I want to work with. Somewhere in this page there are six blocks of text I want to run two operations on apiece: first is finding the verifying the block, then sorting and counting the elements in the block.
This sounds like a job for a pair of handlers to me, but I can’t make them work. I can write the script without the handlers, and it will work, but it is not elegant, it’s a huge script, and it’s a mess to look at and change. I would very much like to get those handlers working.
The error I’m getting is:
AppleScript Syntax error
Expected ", " but found class name.
-2741
in the handler code block, keyed on the word “window” right after "if (search ". If I take the code out of the handler and stick it in the body of the script, everything is fine. Put it in a handler, and things go whacky in short order.
I would very much appreciate any help anyone could offer. Neither Script Editor nor Script Debugger (which I’m just trying out) seems to be of much help with this.
tell application "Tex-Edit Plus"
activate
--Begin timing of the operation. This is finished at the very end of the script
set t to (time of (current date))
--These elements mark where, in the HTML source file, the related info starts
set AmmoStartMarker to "<form name=\"takeammo\" method=\"post\" action=\"/map/safe.do\">"
--These variables initialize the text fields
set AmmoText to ""
--Window 1 contains the HTML source
set name of window 1 to "SourceWindow"
FindInventoryBlock("SourceWindow", AmmoStartMarker, "Ammo block") of me
--Finish timing evaluation
set total to (time of (current date)) - t
display dialog "This script took " & (total as text) & " seconds to complete." with icon note
end tell
on FindInventoryBlock(theName, Marker, errorBlock)
if (search window theName looking for Marker with cases matching) is true then
--We have found the correct section. Test to see if the paragraph of data exists. If it is correctly formatted, the first word of the paragraph will be "<select"
if word 1 of paragraph (4 + ((paragraph offset of selection) of window theName)) of window theName is "<select" then
--This sets AmmoText to the paragraph containing the listing of ammo, which is the fourth paragraph after the paragraph indicated by AmmoStartMarker
return paragraph (4 + ((paragraph offset of selection) of window theName)) of window theName
else
--There is some kind of problem with the data paragraph
display dialog "There is a problem with the data in the " & (errorBlock as text) & "!" with icon note
end if
end if
end FindInventoryBlock
Model: PowerBook PowerPC G4
AppleScript: 1.9.3
Browser: Firefox 2.0.0.6
Operating System: Mac OS X (10.3.9)