Unaltered script quits working after Save

After a minor edit in an AppleScript previously saved in May 2013, it no longer worked. Since the difference between the old script and the new one couldn’t account for the failure, I saved the script with no changes at all, and the saved script still failed. The old version still works fine.

The script starts up OK and appears to stay running (as intended), but it fails to respond to any tell calls. For debugging purposes I installed display dialog statements immediately after each entry point, and none were activated.

Up to this point, all of the editing and saving was done in AppleScript Editor 2.5.1. When the script is saved using Script Debugger (in trial mode), it works perfectly. I’m willing (but not exactly eager) to fork out $199 for Script Debugger, but not without making some effort to solve the problem in AppleScript Editor.

A possible clue is that in May 2013 my OS was 10.6.8, and now it’s 10.8.5. Either AppleScript Editor has changed or it is incompatible with something in 10.8.5.

I’m wondering whether anyone else has encountered such an anomaly.

Model: MacBookPro9,1
AppleScript: 2.2.4
Browser: Chrome 30.0.1599.101
Operating System: Mac OS X (10.8)

There used to be a Applescript version change section at this site I think. I don’t know where it went.

Edited: found it:
http://macscripter.net/viewforum.php?id=41

Edited: there is no 10.6 + yet.

gl,
kel

here the “native” ones:

AppleScript Release Notes: Introduction to AppleScript Release Notes

I wonder if it’s a 64 bit vs. 32 bit thing.

You know, come to think of it. I’ve experienced this. The script would work one time and then it would error on the second run. I think it was a syntax error on the second run.

There are some changes in Lion and Mountain Lion. Could you please post some code

I don’t mind posting the code, but it’s kinda big–375 lines. The guidelines don’t seem to limit the size of posted code, so here goes:

(*	This script uploads regatta schedules, results, and trophy-point totals
 	to the Austin Rowing Club's Live Results website. Its
	four handlers are called by FileMaker running RegattaBase. 
   
	Each of the three upload handlers reads a text file written by RegattaBase, adds html  
	code before and after the file's contents to make a valid html page, and sends the 
	resulting file to the Live Results website.
   
	The initialization handler customizes the html "before" code using arguments
	supplied by RegattaBase. The last argument is the path of the folder to be used
	for the files it reads and writes.
*)

property footer : "<div id=\"footer\"><a name=\"latestResults\"></a>
        <div class=\"floatLeft\">
          <p>Questions or comments about these pages? </p>
          <div class=\"spamVaccineStyle\">
            <p >Contact 
              <script type=\"text/javascript\" inserter=\"Spam Vaccine 1.3\">
<!--
spam_vaccine( new Array(\"\\h\\r\\i\\c\\h\\a\\r\\d\\s\", \"\", \"\\s\\w\\b\\e\\l\\l\", \"\", \"\\n\\e\\t\", \"\"), new Array(\"Ham Richards\"), \"spam_vaccine/\" ) ;
//-->
</script>
              <noscript>
                hrichards<img width=\"11\" height=\"12\" align=\"absmiddle\" border=\"0\" alt=\" -at- \" src=\"spam_vaccine/at_medium.gif\">swbell.net
              </noscript></p>
          </div>
        </div>
   		<a title=\"Austin Rowing Club website\" href=\"http://www.austinrowing.org\" ><img src=\"ARClogo.gif\" alt=\"Austin Rowing Club logo\" name=\"ARClogo\" width=\"78\" height=\"69\" align=\"top\" class=\"smallARClogo\"></a>
    </div> </div>
    <script type=\"text/javascript\">
var MenuBar1 = new Spry.Widget.MenuBar(\"MenuBar1\", {imgDown:\"SpryAssets/SpryMenuBarDownHover.gif\", imgRight:\"SpryAssets/SpryMenuBarRightHover.gif\"});
    </script>
	</body>
</html>"


global preSchedule

property postSchedule : "</dl><p> </p></div>" & footer

global scheduleNote, resultsNote

global preResults

property postResults : "</div>" & footer

global prePoints1, prePoints2

property postPoints : "</table><p> </p></div>" & footer

global uploadFolderPath

property dragon : false

property hostname : "[url=ftp://ftp.austinrowing.org/austinrowing.org/liveresults]ftp.austinrowing.org/austinrowing.org/liveresults[/url]"
property username : "austinrc"
property pwd : "¢¢¢¢¢¢¢¢¢¢¢¢"

on makeHeader(title, regattaType, regattaName, regattaHTMLname, regattaDates, regattaSponsor, regattaLocation) ----------------------------------------
	
	if regattaType = "head" then
		return "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">

<html>

	<head>
		<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">
		<meta name=\"viewport\" content=\"width=device-width\">
	<title>" & regattaName & ": " & title & "</title>
		<style type=\"text/css\" media=\"screen\">
		<!--
-->
		</style>
		<link href=\"site.css\" rel=\"stylesheet\" type=\"text/css\">
<script type=\"text/javascript\" src=\"spam_vaccine/spam_vaccine.js\" inserter=\"Spam Vaccine 1.3\"></script>
<script src=\"SpryAssets/SpryMenuBar.js\" type=\"text/javascript\"></script>
<link href=\"SpryAssets/SpryMenuBarHorizontal.css\" rel=\"stylesheet\" type=\"text/css\">
<link href=\"swmq.css\" rel=\"stylesheet\" type=\"text/css\">
</head>

	<body bgcolor=\"#ffffff\">
    <div class=\"container\">
		<div id=\"header\">
		  <h1>" & regattaHTMLname & "</h1>
				<h2>" & regattaLocation & "<br> " & regattaDates & "</h2>
          <div id=\"linkBar\">
            <ul id=\"MenuBar1\" class=\"MenuBarHorizontal\">
              <li><a href=\"day1results.html\">Results</a></li>
              <li><a href=\"day1schedule.html\">Schedule</a></li>
              <li><a href=\"penaltyGuide.html\">Penalties</a></li>
            </ul>
          </div>
		</div>
		<div id=\"content\">"
	else
		return "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
	<head>
		<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">
		<meta name=\"viewport\" content=\"width=device-width\">
	<title>" & regattaName & ": " & title & "</title>
		<style type=\"text/css\" media=\"screen\">
		<!--
-->
		</style>
		<link href=\"site.css\" rel=\"stylesheet\" type=\"text/css\">
<script type=\"text/javascript\" src=\"spam_vaccine/spam_vaccine.js\" inserter=\"Spam Vaccine 1.3\"></script>
<script src=\"SpryAssets/SpryMenuBar.js\" type=\"text/javascript\"></script>
<link href=\"swmq.css\" rel=\"stylesheet\" type=\"text/css\">

<link href=\"SpryAssets/SpryMenuBarHorizontal.css\" rel=\"stylesheet\" type=\"text/css\">
</head>
	<body bgcolor=\"#ffffff\">
    <div class=\"container\">
		<div id=\"header\">
		  <h1>" & regattaHTMLname & "</h1>
          <h2>" & regattaLocation & "<br>" & regattaDates & "</h2>
<p>sponsored by " & regattaSponsor & "</p>
          <div id=\"linkBar\">
            <ul id=\"MenuBar1\" class=\"MenuBarHorizontal\">
              <li><a href=\"index.html\" title=\"Home page\">Home</a></li>
              <li><a href=\"day12schedule.html\" title=\"note on schedules\" class=\"MenuBarItemSubmenu\">Schedule</a>
                <ul>
                  <li><a href=\"day1schedule.html\" title=\"Saturday schedule\">Saturday </a></li>
                  <li><a href=\"day2schedule.html\" title=\"Sunday schedule\">Sunday</a></li>
                </ul>
              </li>
              <li><a href=\"day12results.html\" title=\"note on Results\" class=\"MenuBarItemSubmenu\">Results</a>
                <ul>
                  <li><a href=\"day1DBresults.html\" title=\"Dragon Boat results\">Dragon Boats</a></li>
                  <li><a href=\"day12results.html\" title=\"Rowing results\" class=\"MenuBarItemSubmenu\">Rowing</a>
                    <ul>
                      <li><a href=\"day1results.html\" title=\"Saturday rowing results\">Saturday</a></li>
                      <li><a href=\"day2results.html\" title=\"Sunday rowing results\">Sunday</a></li>
                    </ul>
                  </li>
                </ul>
              </li>
              <li><a href=\"pointsNote.html\" title=\"note on Points\" class=\"MenuBarItemSubmenu\">Points</a>
                <ul>
                  <li><a href=\"pointsJuniors.html\" title=\"Juniors points\">Juniors</a></li>
                  <li><a href=\"pointsMasters.html\" title=\"Masters points\">Masters</a></li>
                  <li><a href=\"pointsAll.html\" title=\"All points\">All</a></li>
                </ul>
              </li>
            </ul>
          </div>
		</div>
		<div id=\"content\">"
	end if
	
end makeHeader -------------------------------------------------------------------------------------------------------------

on initialize(regattaType, regattaName, regattaHTMLname, regattaDates, regattaSponsor, regattaLocation, uFP) -------------------------------------------------------------------------------------
	
	set preSchedule to makeHeader("Schedule", regattaType, regattaName, regattaHTMLname, regattaDates, regattaSponsor, regattaLocation)
	
	set preResults to makeHeader("Results", regattaType, regattaName, regattaHTMLname, regattaDates, regattaSponsor, regattaLocation)
	
	set prePoints1 to makeHeader("Points", regattaType, regattaName, regattaHTMLname, regattaDates, regattaSponsor, regattaLocation) & "<H2>Trophy Point standings for "
	
	set prePoints2 to " events</H2>
			<h4>Points are computed using the USRowing formula
			 <a title=\"USRowing Rules of Rowing\"
			 href=\"http://www.usrowing.org/Libraries/Referees/2013RORfinalweb.sflb.ashx\">
			 (USRowing 2013 Rules of Rowing, page 66)</a>.</h4>"
	
	set uploadFolderPath to uFP
	
	set initialized to true
	
end initialize --------------------------------------------------------------------------------------

on uploadDragonResults(dayNumber, doUpload, resultsNote)
	set dragon to true
	uploadResults(dayNumber, doUpload, resultsNote)
end uploadDragonResults ------------------------------------------------


on uploadResults(dayNumber, doUpload, resultsNote) -----------------------------------------------------------------------
	
	local resultsTEXTpath, resultsTEXTfile, resultsHTMLpath, resultsHTMLfile, resultsFileName
	
	if dragon then
		set dbTag to "DB"
	else
		set dbTag to ""
	end if
	
	set resultsTEXTpath to (uploadFolderPath & dbTag & "results.tab") -- input file
	
	set resultsFileName to "day" & dayNumber & dbTag & "results.html"
	
	set resultsHTMLpath to (uploadFolderPath & resultsFileName) -- output file
	
	try
		set resultsTEXTfile to open for access file resultsTEXTpath
	on error msg
		display dialog "regattaUploads/uploadResults: " & msg buttons {"QUIT"} default button "QUIT"
		close access file resultsTEXTpath
		return
	end try
	
	try
		set resultsHTMLfile to open for access file resultsHTMLpath with write permission
	on error msg
		display dialog "regattaUploads/uploadResults: " & msg buttons {"QUIT"} default button "QUIT"
		close access file resultsHTMLpath
		return
	end try
	
	set eof resultsHTMLfile to 0 -- erase it if it exists
	
	-- build file results.html
	write preResults to resultsHTMLfile as «class utf8»
	
	if dragon then
		write ("<H2>Dragon Boat Results as of " & timeNow() & "</H2>" & return & return) to resultsHTMLfile as «class utf8»
	else
		write ("<H2>Results as of " & timeNow() & "</H2>" & return ¬
			& "<H2>" & resultsNote & "</H2>" & return & return ¬
			& ¬
			"<H2><a href=\"#latestResults\">Latest Results</a></H2>") to resultsHTMLfile as «class utf8»
	end if
	write (read resultsTEXTfile as «class utf8») to resultsHTMLfile as «class utf8»
	write postResults to resultsHTMLfile as «class utf8»
	
	close access resultsTEXTfile
	close access resultsHTMLfile
	
	-- upload results.html
	set posixResultsPath to POSIX path of resultsHTMLpath
	
	set ftpScript to ("curl -T " & quoted form of posixResultsPath & " ftp://" & username & ":" & pwd & "@" & hostname & "/" & resultsFileName)
	
	if doUpload > 0 then do shell script ftpScript
	
	set dragon to false
	
end uploadResults ------------------------------------------------------------------------------


on uploadPoints(tag, doUpload, pointsNote) -------------------------------------------------------------------------------
	-- tag specifies whether point totals are for Junior events, Masters events, or all events.
	-- Its value should be "Juniors", "Masters", or "All".
	
	local rpPath, rpFile, rpLine, wpPath, wpFile, wpLine
	
	set rpPath to uploadFolderPath & "rawPoints" & tag & ".tab"
	set wpPath to uploadFolderPath & "weightedPoints" & tag & ".tab"
	set pointsPath to uploadFolderPath & "points" & tag & ".html"
	
	try
		set rpFile to open for access file rpPath
	on error msg
		display dialog "regattaUploads/uploadPoints: " & msg buttons {"QUIT"} default button "QUIT"
		close access file rpPath
		return
	end try
	
	try
		set wpFile to open for access file wpPath
	on error msg
		display dialog "regattaUploads/uploadPoints: " & msg buttons {"QUIT"} default button "QUIT"
		close access file wpPath
		return
	end try
	
	try
		set pointsFile to open for access file pointsPath with write permission
	on error msg
		display dialog "regattaUploads/uploadPoints: " & msg buttons {"QUIT"} default button "QUIT"
		close access file pointsPath
	end try
	
	set eof pointsFile to 0 -- erase if it exists
	
	write -257 to pointsFile as small integer starting at 0 -- Unicode BOM
	
	write prePoints1 to pointsFile as Unicode text
	write tag to pointsFile as Unicode text
	write prePoints2 to pointsFile as Unicode text
	
	
	write ("<H3>" & timeNow() & "</H3>" & return & return & "<table width=\"80%\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\">" & return) to pointsFile as Unicode text
	write "<tr><td align=\"center\"><b><font size=\"+1\">Total Points</font></b></td><td></td><td></td><td align=\"center\"><b><font size=\"+1\">Points per Entry</font></b></td></tr>" to pointsFile as Unicode text
	
	set endFile to false
	
	repeat until endFile
		
		try
			set rpLine to read rpFile before return
			set wpLine to read wpFile before return
			write rpLine to pointsFile as Unicode text
			write wpLine to pointsFile as Unicode text
			write return to pointsFile as Unicode text
			
		on error
			set endFile to true
			close access rpFile
			close access wpFile
		end try
		
	end repeat
	
	write postPoints to pointsFile as Unicode text
	close access pointsFile
	
	-- upload Points.html
	set posixPointsPath to POSIX path of pointsPath
	set ftpScript to ("curl -T " & quoted form of posixPointsPath & " ftp://" & username & ":" & pwd & "@" & hostname & "/points" & tag & ".html")
	
	if doUpload > 0 then do shell script ftpScript
	
end uploadPoints -----------------------------------------------------------------------------------------------------


on uploadSchedule(dayNumber, doUpload, scheduleNote) ------------------------------------------------------------------------------------
	
	local scheduleTEXTpath, scheduleTEXTfile, scheduleHTMLpath, scheduleHTMLfile
	
	set scheduleTEXTpath to (uploadFolderPath & "schedule.tab") -- input file
	
	set scheduleHTMLpath to (uploadFolderPath & "day" & dayNumber & "schedule.html") -- output file
	
	try
		set scheduleTEXTfile to open for access file scheduleTEXTpath
	on error msg
		display dialog "regattaUploads/uploadSchedule: " & msg buttons {"QUIT"} default button "QUIT"
		close access file scheduleTEXTpath
		return
	end try
	
	try
		set scheduleHTMLfile to open for access file scheduleHTMLpath with write permission
	on error msg
		display dialog "regattaUploads/uploadSchedule: " & msg buttons {"QUIT"} default button "QUIT"
		close access file scheduleHTMLpath
		return
	end try
	
	set eof scheduleHTMLfile to 0 -- erase file if it exists
	
	-- build file schedule.html
	write preSchedule to scheduleHTMLfile as «class utf8»
	write ("<H2>Race Schedule as of " & timeNow() & "</H2>" & return ¬
		& "<H2>" & scheduleNote & "</H2>" & return ¬
		& "<H3>Numbers in parentheses are <i>handicaps</i>.</H3>" & "<H3>Letters (<I>A</I>, <i>B</I>, <I>C</I>,...) following team names are <i>seeds</i>.</H3><DL>") ¬
		to scheduleHTMLfile as «class utf8»
	write (read scheduleTEXTfile as «class utf8») to scheduleHTMLfile as «class utf8»
	write postSchedule to scheduleHTMLfile as «class utf8»
	
	close access scheduleTEXTfile
	close access scheduleHTMLfile
	
	-- upload schedule.html
	set posixSchedulePath to POSIX path of scheduleHTMLpath
	
	set ftpScript to ("curl -T " & quoted form of posixSchedulePath & " ftp://" & username & ":" & pwd & "@" & hostname & "/day" & dayNumber & "schedule.html")
	
	if doUpload > 0 then do shell script ftpScript
	
	return ftpScript
	
end uploadSchedule ----------------------------------------------------------------------------------


on timeNow() --------------------------------------------------------------------------------------
	-- create time and day string, omitting seconds
	set t to time string of (current date)
	set n to length of t
	return (((characters 1 thru (n - 6) of t) & (characters (n - 2) thru n of t)) as text) & " " & date string of (current date)
end timeNow --------------------------------------------------------------------------------------

When compiled in AppleScript Editor it falls flat. Compiled in Script Debugger it works perfectly.

Comments welcome,

–Ham

Hello.

It seems to me that your script may at some stage not be save-able, because of internal table overflow.

If I were you, I’d try declaring

property parent : AppleScript

at top of it.

I’d also rework all the long texts from being properties, into local variables, in order to minimize the context that is saved. When reworking the texts into local variables, I’d also try to declare them within the handlers that uses them, if that is a viable approach. For instance: you have a pretty long text in one of your return statements. Try declaring the text as different chunks, in local variables, then concatenate the local variables, and the new one in the return statement.

I hope this helps.

In the script the explicit or implicit run handler is missing

One thought here is that a disastrous change was made to AppleScript Editor in OS 10.7, making it possible to save scripts with uncompiled changes. This was exacerbated (or possibly caused) by the introduction of Versions, which makes any edits in a document permanent unless they’re explicitly reverted. The buttons in the dialogs displayed when the application’s quit sometimes offer the opportunity to “Revert Changes”, sometimes to “Delete and Quit”, and sometimes to “Quit Anyway”. If, like me, you’re used to not reading these because they’ve always said “Discard Changes”, you could end up with unusable script files. (The only use I’ve found for Versions so far is to undo the problems it’s caused!) It’s safest always explicitly to revert any changes you don’t want to keep, recompile the script, and immediately resave it.

In the script itself, there are loads of operations on files which have been opened for access with write permission. None of these operations are in ‘try’ statements. Any errors in their execution will stop the script without closing the write-permission accesses and it won’t be possible to open those files again with write permission until the application running the script is quit and surrenders its accesses to the files. If the script’s running as a stay-open application, it’ll mean quitting the applet itself. And then fixing the problem, of course.

Your timeNow() handler assumes that the computer’s configured for a 12-hour clock, that AppleScript’s text item delimiters are at their default value, and that midnight will not be passed between the two calls to ‘current date’; but that’s unlikely to be contributing to the current problem. :wink: