Sample ScriptEditor scripting

Short example of using Script Editor scripting to open dictionaries inside the Script Editor.

OS version: OS X

tell application "Script Editor"
    set theSelectedText to contents of selection of front document
    if theSelectedText is "" then
        choose file with prompt "Select items to open their dictionaries: " of
type "APPL"
    else
        tell me to get path to application theSelectedText
    end if
    open result
end tell

Hello-

Edit:I have compiled a set of double and single space routines for Script Debugger 4.5, AppleScript Editor 2 and Smile. Thanks to Ed Stockly of! AppleScript Users mailing list and J.Stewart from SD-Talk users mailing lis.

The common routines are the first code block in this post, you can either load them as a library or past them into the handlers you need.

A natural next step would be to to only single or double space a selection, but that must wait.

The LIbrary


on doubleSpace(theText) -- thanks to Ed Stockly of AppleScript's user groups.
	local tids
	set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
	set theText to text items of theText
	set AppleScript's text item delimiters to {return & return}
	set theText to theText as text
	set AppleScript's text item delimiters to tids
	return theText
end doubleSpace

on singleSpace(theText)
” © McUsr 2010 and put in the public domain
	script o
		property l : {}
	end script
	local tids, justRemoved, bummer
	set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ""}
	set AppleScript's text item delimiters to return
	set o's l to text items of theText
	
	set justRemoved to false
	repeat with i from 1 to (count o's l)
		set bummer to false
		
		tell item i of o's l
			repeat with i from 1 to (count it)
				if character i of its contents is not tab then
					set bummer to true
					exit repeat
				end if
			end repeat
		end tell
		if bummer is false and justRemoved is false then
			set item i of o's l to missing value
			set justRemoved to true
		else
			set justRemoved to false
		end if
		
	end repeat
	set theText to (o's l's text) as text
	set AppleScript's text item delimiters to tids
	return theText
end singleSpace

Single Space for AppleScript Editor


property sctext : (load script alias "Macintosh HD:Users:McUsr:Library:Scripts:Modules:ScriptEditorTextLib.scpt")
try
	tell application "AppleScript Editor"
		
		tell its document 1
			activate
			
			set theText to its text
			set its text to sctext's singleSpace(theText)
		end tell
	end tell
on error e number n
	tell me
		activate
		display dialog e & ":" & n
	end tell
end try

Double Space for AppleScript Editor


property sctext : (load script alias "Macintosh HD:Users:McUsr:Library:Scripts:Modules:ScriptEditorTextLib.scpt")
try
	tell application "AppleScript Editor"
		tell its document 1
			activate
			set theText to its text
			set its text to sctext's doubleSpace(theText)
		end tell
	end tell
on error e number n
	tell me
		activate
		display dialog e & ":" & n
	end tell
end try

Single Space for Script Debugger 4.5


property sctext : (load script alias "Macintosh HD:Users:McUsr:Library:Scripts:Modules:ScriptEditorTextLib.scpt")
try
	tell application "Script Debugger 4.5"
		set theText to script source of document 1
		set script source of document 1 to sctext's singleSpace(theText)
	end tell
on error e number n
	tell me
		activate
		display dialog e & ":" & n
	end tell
end try

Double Space for Script Debugger 4.5


property sctext : (load script alias "Macintosh HD:Users:McUsr:Library:Scripts:Modules:ScriptEditorTextLib.scpt")
try
	tell application "Script Debugger 4.5"
		set theText to script source of document 1
		set script source of document 1 to sctext's doubleSpace(theText)
	end tell
on error e number n
	tell me
		activate
		display dialog e & ":" & n
	end tell
end try

Single Space for Smile


property sctext : (load script alias "Macintosh HD:Users:McUsr:Library:Scripts:Modules:ScriptEditorTextLib.scpt")
try
	tell application "Smile"
		
		tell its front window
			activate
			set theText to its text -- of its document 1
			set its text to sctext's singleSpace(theText)
		end tell
	end tell
on error e number n
	tell me
		activate
		display dialog e & ":" & n
	end tell
end try

Double Space for Smile


property sctext : (load script alias "Macintosh HD:Users:McUsr:Library:Scripts:Modules:ScriptEditorTextLib.scpt")

try
	tell application "Smile"
		
		tell its front window
			activate
			set theText to its text -- of its document 1
			set its text to sctext's doubleSpace(theText)
		end tell
	end tell
on error e number n
	tell me
		activate
		display dialog e & ":" & n
	end tell
end try

Hello.

Updated the post above with Single and Double Space routines for AppleScript Edtitor 2, Script Debugger 4.5 and Smile.
Enjoy.