My scripts are getting garbled!

I’ve opened several script that I’ve made recently only to find them garbled. See sample below. Does anyone know why this is happening?

Ex.

tell application "Finder"
	activate
	tell text of «class TxtD» 1
		«event R*chRepl» "zzzzzzz" given «class Repl»:«class pusl» as text, «class Opts»:{«class SMod»:«constant SModLtrl», «class STop»:true, «class Wrap»:false, «class Rvrs»:false, «class Case»:false, «class Wrds»:false, «class ExSl»:false}
	end tell
	save document 1
end tell

Here’s another one!

If you look at this thread, you’ll see what its supposed to look like:
http://macscripter.net/viewtopic.php?id=43701

But when I open it, it’s garbled. even when I try to revert to and older one that I knw was good, they’re all garbled too. HELP!

--Select the product to be deleted first

tell application "Finder"
	set myProduct to the «class pusl» of «class TxtW» 1
	set tagLength to 41 + 1
	set colorCodeLength to 8
	set specialClassesLength to 2
	set thumbsLine to "<thumbs>"
	set headlineColors to "headlineColors"
	set subheadlineColors to "subheadlineColors"
	set legalColors to "legalColors"
	set specialClasses to "specialClasses"
	-------------------------------------------------
	--find the line that the thumbs tag is on
	«event R*chFind» thumbsLine with «class SelM» given «class FnIn»:text 1 of «class TxtW» 1, «class Opts»:{«class SMod»:text, «class STop»:true, «class Rvrs»:false, «class Case»:false, «class Wrds»:false, «class ExSl»:false}
	copy the «class SLin» of «class pusl» of window 1 to thumbsLineCount
	-------------------------------------------------
	--find the line that the desired product tag is on
	«event R*chFind» myProduct with «class SelM» given «class FnIn»:text 1 of «class TxtW» 1, «class Opts»:{«class SMod»:text, «class STop»:true, «class Rvrs»:false, «class Case»:false, «class Wrds»:false, «class ExSl»:false}
	copy the «class SLin» of «class pusl» of window 1 to productLineCount
	
	-- and subtract it from the thumbs line
	set productNumber to productLineCount - thumbsLineCount
	set productColor to productNumber - 1
	-----------------------------------------------
	--Delete the entire line that the product is on
	set deleteProductLine to line productLineCount of «class TxtW» 1
	delete every character of deleteProductLine
	-------------------------------------------------
	--LINE COUNT 1
	--find the text color tag and get its line number and set var lineCount1
	«event R*chFind» headlineColors with «class SelM» given «class FnIn»:text 1 of «class TxtW» 1, «class Opts»:{«class SMod»:text, «class STop»:true, «class Rvrs»:false, «class Case»:false, «class Wrds»:false, «class ExSl»:false}
	copy the «class SLin» of «class pusl» of window 1 to lineCount1
	
	--select first char of chosen product color
	select character (productColor * colorCodeLength + tagLength) of line lineCount1 of text of window 1
	set startMark to «class Ofse» of «class pusl» of «class TxtW» 1
	
	-- and find next pipe char and extend selection
	set targetColor to «event R*chFind» "[|]" with «class ExSl» given «class FnIn»:text 1 of «class TxtW» 1, «class Opts»:{«class SMod»:«constant SModGrep», «class STop»:false, «class Wrap»:false, «class Rvrs»:false, «class Case»:true}
	set endMark to «class Ofse» of targetColor's «class MSpc»
	select (characters startMark thru endMark) of «class TxtW» 1
	set text of «class pusl» to ""
	-----------------------------------------------
	--LINE COUNT 2
	--find the text color tag and get its line number and set var lineCount2
	«event R*chFind» subheadlineColors with «class SelM» given «class FnIn»:text 1 of «class TxtW» 1, «class Opts»:{«class SMod»:text, «class STop»:true, «class Rvrs»:false, «class Case»:false, «class Wrds»:false, «class ExSl»:false}
	copy the «class SLin» of «class pusl» of window 1 to lineCount2
	
	--select first char of chosen product color
	select character (productColor * colorCodeLength + tagLength) of line lineCount2 of text of window 1
	set startMark to «class Ofse» of «class pusl» of «class TxtW» 1
	
	-- and find next pipe char and extend selection
	set targetColor to «event R*chFind» "[|]" with «class ExSl» given «class FnIn»:text 1 of «class TxtW» 1, «class Opts»:{«class SMod»:«constant SModGrep», «class STop»:false, «class Wrap»:false, «class Rvrs»:false, «class Case»:true}
	set endMark to «class Ofse» of targetColor's «class MSpc»
	select (characters startMark thru endMark) of «class TxtW» 1
	set text of «class pusl» to ""
	-----------------------------------------------
	--LINE COUNT 3
	--find the text color tag and get its line number and set var lineCount3
	«event R*chFind» legalColors with «class SelM» given «class FnIn»:text 1 of «class TxtW» 1, «class Opts»:{«class SMod»:text, «class STop»:true, «class Rvrs»:false, «class Case»:false, «class Wrds»:false, «class ExSl»:false}
	copy the «class SLin» of «class pusl» of window 1 to lineCount3
	
	--select first char of chosen product color
	select character (productColor * colorCodeLength + tagLength) of line lineCount3 of text of window 1
	set startMark to «class Ofse» of «class pusl» of «class TxtW» 1
	
	-- and find next pipe char and extend selection
	set targetColor to «event R*chFind» "[|]" with «class ExSl» given «class FnIn»:text 1 of «class TxtW» 1, «class Opts»:{«class SMod»:«constant SModGrep», «class STop»:false, «class Wrap»:false, «class Rvrs»:false, «class Case»:true}
	set endMark to «class Ofse» of targetColor's «class MSpc»
	select (characters startMark thru endMark) of «class TxtW» 1
	set text of «class pusl» to ""
	-----------------------------------------------
	--LINE COUNT 4
	--find the text color tag and get its line number and set var lineCount4
	«event R*chFind» specialClasses with «class SelM» given «class FnIn»:text 1 of «class TxtW» 1, «class Opts»:{«class SMod»:text, «class STop»:true, «class Rvrs»:false, «class Case»:false, «class Wrds»:false, «class ExSl»:false}
	copy the «class SLin» of «class pusl» of window 1 to lineCount4
	
	--select first char of chosen product color
	select character (productColor * specialClassesLength + tagLength) of line lineCount4 of text of window 1
	set startMark to «class Ofse» of «class pusl» of «class TxtW» 1
	
	-- and find next pipe char and extend selection
	set targetColor to «event R*chFind» "[|]" with «class ExSl» given «class FnIn»:text 1 of «class TxtW» 1, «class Opts»:{«class SMod»:«constant SModGrep», «class STop»:false, «class Wrap»:false, «class Rvrs»:false, «class Case»:true}
	set endMark to «class Ofse» of targetColor's «class MSpc»
	select (characters startMark thru endMark) of «class TxtW» 1
	set text of «class pusl» to ""
	
end tell

--replace (characters 114 thru 121 of line 14) of text window 1 using ""

It has something to do with the way Applescript Editor is reading them in. They still work in the application when not run from script editor. I re-opened it in Script Editor and it looked fine then I closed it and reopened and it was garbled again.

I cleaned out my font caches and it still has a problem so I guess that wasn’t it.

Hello.

It seems to me, that the dictionary of BBEdit isn’t available have you removed it from the Library of Dictonaries of Script Editor?

Other than that, I have no clues, as to what may have happened.

Hi.

The scripts you’ve posted have BBEdit/TextWrangler codes inside “Finder” ‘tell’ blocks. What did you write originally?

Hello, I didn’t see that.

You really shouldn’t nest tell application blocks, and you can’t use events (commands) or classes and properties from one application inside another applications tell block. The dictionaries, are application specific, save the standard suite, but even that one should be inside the application tell block, of the application from which dictionary you used.

I think McUsrII’s conjecture about BBEdit’s dictionary not being available is probably closer to the mark than my observation about the “Finder” ‘tell’ blocks. The only way I can exactly reproduce the “garbled” versions of the scripts is to open them in Script Editor on a machine where BBEdit isn’t installed (or TextWrangler in my case) and choose the Finder in the ‘choose application’ dialog which appears.

When opening scripts, Script Editor needs to be able to access the scripted applications’ scripting dictionaries so that it can get the keywords corresponding to the compiled tokens to display on the screen. Otherwise it can only display the tokens, which is what has happened above. If you change “Finder” to “BBEdit” and recompile (on a machine with BBEdit installed), you should see the keywords again.

That is what I thought and also what you actually meant by your first post.

Contacts must be running when we try to compile a script supposed to drive it.

Maybe it’s the same for BBEdit.

Yvan KOENIG (VALLAURIS, France) lundi 2 mars 2015 18:45:02

I had BBedit installed the entire time. Sometimes the script would open correctly and sometimes not. I re-installed BBedit from the original dmg so hopefully, that will fix it.

Yes, but you don’t appear to have a tell application “BBEdit” statement anywhere to tell the script where to look for the terminology.

Hello.

Just for the record, should you wish to share this script with someone that doesn’t have BBEdit, then you should be able to change tell application “BBEdit” with tell application “TextWrangler” and it should work equally well. One thing however that I have experienced with TextWrangler, is that it pays off to open documents in a separate window with the “open” command using the opening in new_window option. This is because there can be problems during closing a text document from a project window in some circumstances, at least when you do it manually.