Scripting Script Debugger 4.5

Hello.

I’m trying to write a script which doublespaces the lines of the source text, but I’m having a problem with setting the altered source text back. -Any of you guys who knows the right incantation?

This is really work in progress so I only need help with setting the source text to theText

Thanks.


set AppleScript's text item delimiters to ""
set frontAppBid to bid's frontmostBundleId()
haltIfAppIsNotSupported(frontAppBid)
-- return
try
	tell application id frontAppBid
		
		tell its script window 1
			activate
			
			if frontAppBid is "com.apple.ScriptEditor2" then
				set theText to every paragraph of text of its document 1
			else if frontAppBid is "com.latenightsw.ScriptDebugger" then
				set theText to script source of its document
				
			end if
			set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
			set theText to text items of theText
			-- display dialog "here"
			
			repeat with aPar in theText
				set contents of aPar to "" & aPar & return
			end repeat
			-- set AppleScript's text item delimiters to tids
			set theText to theText as text
			tell its document
				
				set script source of it to a reference to theText
				-- the last thing I tested for
			end tell -- of script window 1 to theText
		end tell
		set AppleScript's text item delimiters to tids
	end tell
on error e number n
	tell me
		activate
		display dialog e & ":" & n
	end tell
end try

Hi,

I doubt that the code works with Script Editor, because SE doesn’t know script window.
I would avoid those large object tell blocks, it often could cause unexpected behavior.
tell application is also delicate, you must make sure that the terminology can be resolved properly at compile time.
The its and of it statements are actually not needed and I guess a reference to , too

Hello. Stefan

Its’ really just something I have crammed together on the fly, just to make the ScriptDebugger part work.
It is not intended to be like this at all when it is finished :slight_smile: I’m just trying to stuff the expanded source back into Script Debugger for the moment. :o

It is odd, I can read that property, but it fails when I try to assign it back. Luckily this is just a side project. But I still want the ability to double space and single space AppleScripts within any editor. I have noticed that it is of great help to have lots of space when you read code. :slight_smile:

Thanks.

Edit What I really got out of this post is that if I write a solution which targets several apps, then I must be sure that the users have those apps installed, before they can compile it. -As I distribute here at Macscripter.Net.
If I on the other hand shipped away a compiled script, which did compile on my machine, then the user without app XYZ, would never notice a thing, -until he recompiled.

I find it strange that it works like this with applications, but not with AppleScript. I have heard people state that code blocks that contains Leopard specific code compiles and runs fine on Tiger machines, as long as the code isnt’t touched run time. (I’m thinking of character id.)

I will anyway have to rethink the thoughts of how wonderful it would be to have just one script to maintain.

Hello.

I have created singe and double spacing routines for AppleScript Editor 2 Script Debugger 4.5 and Smile.
They can be found here