Script fails if I do not Compile between each Run - Huh? Why is this?

Call me confused. I can run this script successfully once. But if I Run it again a 2nd time, it fails with the following error:

AppleScript Error
<> does not understand the savePrinter message.

Within Script Editor, if I Compile between each attempt to Run, it will work just fine. If I do not Compile between each Run, the error occurs. What is causing this and how do I fix it?

Thanks for all your help guys.


on savePrinter()
	set savePrinter to null
	tell application "Printer Setup Utility"
		set savePrinter to current printer
		set psPrinter to null
		set psPrinters to printers whose kind is "PageSender-Fax"
		if (count psPrinters) > 0 then
			set psPrinter to item 1 of psPrinters
		end if
		if psPrinter is not null then
			set current printer to psPrinter
		end if
	end tell
end savePrinter

savePrinter() of me

tell application "PageSender Fax Center"
	set thePreset to make new preset at end of every preset
	tell thePreset
		set application name to "TextWrangler"
		set theFaxInfo to make new fax info at end of every fax info
		tell theFaxInfo
			set regarding to "Sample Regarding"
			set message to "Sample Message"
			set has cover to false
		end tell
		set theFirstRecipient to make new fax recipient at end of every recipient
		tell theFirstRecipient
			set country code to "1"
			set phone number to "949-709-7704"
			set name to "Robert Ameeti"
			set company to "Test Company"
			set fax service to efax
		end tell
	end tell
	-- Save the preset to a file
	save thePreset
	-- Delete the preset from memory
	delete thePreset
end tell
tell application "TextWrangler"
	set licensePath to "/Applications/PageSender Fax Center.app/Contents/Resources/License Agreement.txt"
	print {POSIX file licensePath}
end tell

The problem is, you call the handler savePrinter() and then you set it to null.
Use a different variable name, then it will work.


on savePrinter()
   set savedPrinter to null
   tell application "Printer Setup Utility"
       set savedPrinter to current printer
       set psPrinter to null
       set psPrinters to printers whose kind is "PageSender-Fax"
       if (count psPrinters) > 0 then
           set psPrinter to item 1 of psPrinters
       end if
       if psPrinter is not null then
           set current printer to psPrinter
       end if
   end tell
end savePrinter

Note: the of me suffix in the savePrinter() line is not needed unless the handler call is within an application tall block