A Server to let you quickly find handlers in your libraries - overview

Hello.

You need to install Satimage.osax in order to use this, be sure to install the 64-bit version if you run Snow Leopard.

What it does

It lets you list all the handlers in a Library or script file (the current script in your fav. script editor) and takes you directly to that position. From that position you can edit, copy or just view the handler.

This can be very useful if you either use libraries, or has lots of handlers in “Clippings files”. You may also have “snippets” within some artificial handler which name is a description of its contents.

One script is provided to navigate in the current file, one script for navigating a script of your choice.

What it is
This is a partial project for the LIbraryLoader, and will be incorporated in it by the time I have written the parts
that extracts all libraries from a Script Server. It is however useful in its own right though. It uses a second or so to display the handlers of a huge script library. After initial load and parsing of the file the server will retain it for 2 hours, so that subsequent accesses are fast enough. The server will reload it, if the file has been updated after its last “rendering”.

The server works equally well with AppleScript Editor, Script Debugger 4.5 and Smile. Scripts to use it with any of those are provided. The scripts are still clumsy to use. It will really shine from the LIbraryLoader. :slight_smile:

I recommend that you assign the script for browsing the current file to the shortcut key ctrl option L.
The other script that lets you choose a file, is really “goner” as soon as I have implemented it in LIbraryLoader.

I hope for some feedback from any of you who tries it.

The LibraryLister should be saved as a stay open faceless applet. Use DockDogder to make it faceless easily. Or even better: use Luther fullers great tool for making app bundles: you can download from here.

What remains

I don’t think this version will run under any other OS than Snow Leopard: will be fixed.

It needs to be localized.

There are no sounds :frowning:

It is not possible to copy a handler signature to to clipboard. (The name of the handler together with its parameters.)

There is no way to see the descriptions of the handlers and objects yet. I haven’t really started figuring that out.
but as the default behavior is to take you to that handler in the script file, and I haven’t thought out any thing for
the script libraries which comes with separate documentation yet.

The full parsing of Script Servers are not implemented yet.

Graphical rendering of the structure of a script library (Diagram) is not implemented yet.

You can’t choose from previously selected files yet.

Every one of this features will come real soon

Further information can be found in this thread

I you want a notification about the LibraryLister when updates are made, then post a replay and say hi, or something related to it, you will then be given opportunity to subscribe to the topic. When I update it, I’ll post what I have done, and you will get that message in your mail box.

Bugs

  • You will get a mismatch with regards to the position of a handler or script object if you have literals like “\t” or “\r” or “\n” in your code. That is due to osadecompile which translates the literals which consists of two characters into one single character. The reported position after one such character will be one less than reality and so on for the next encountered character literals. If you want and need correct positions, then you have to find alternatives to using these literals.

¢ It doesn’t detect block comment tags that are within strings “(*” and “*)”, which means that if you have just as start or end block comment tag in a string between two real comments, or before or or after one, then the block comments will be perceived as unbalanced and it may lead to inaccuracies. This is the place to look if your handlers or script objects doesn’t turn up in the list of entities.

I you have block comments in strings, your last resort is to declare a balancing string with the missing tag in, within
that same scope of code.

These issues will not be fixed by any other means.

The Library Lister

The script for the LibraryLister application has moved to post #7 in this thread.

Scripts to list handlers and navigate to it in current file

AppleScript Editor 2.x

tell application "AppleScript Editor"
	if (count its documents) is greater than 0 then
		set thisScript to POSIX file (path of its front document) as alias -- as Unicode text
	else
		return
	end if
end tell

tell application "LibraryLister"
	set myRes to getPosForEntity(thisScript)
end tell

if myRes is not false then
	
	tell application "AppleScript Editor"
		tell its window 1 to activate
		tell its document 1
			set selection to insertion point myRes -- Ed Stockly Thanks!
			tell application "System Events"
				tell window 1 of application process "AppleScript Editor"
					tell its window 1
						key code 124
					end tell
				end tell
			end tell
		end tell
	end tell
end if

Script Debugger 4.5


tell application "Script Debugger 4.5"
	if (count its documents) is greater than 0 then
		set filenm to file spec of its document of its script window 1 as alias
	else
		return
	end if
end tell

tell application "LibraryLister"
	set myRes to getPosForEntity(filenm)
end tell

if myRes is not false then
	
	tell application "Script Debugger 4.5"
		tell its window 1
			activate
			set character range of selection of (its document) to {myRes, 1}
			tell application "System Events"
				tell application process "Script Debugger 4.5"
					tell its window 1
						key code 124
					end tell
				end tell
			end tell
		end tell
	end tell
end if

Smile



tell application "Smile"
	if (count its script windows) is greater than 0 then
		set thisScript to path name of its front window as alias -- as Unicode text
	else
		return
	end if
end tell

tell application "LibraryLister"
	set myRes to getPosForEntity(thisScript)
end tell

if myRes is not false then
	tell application "Smile"
		tell its window 1
			activate
			set its selection to {myRes, 1}

			tell application "System Events"
				tell application process "Smile"
					tell its window 1
						key code 124
					end tell
				end tell
			end tell
		end tell
	end tell
end if

Script so list handlers of a script by choice and navigate to that handler

AppleScript Editor 2.x


set thisScript to (choose file)
tell application "LibraryLister"
	set myRes to getPosForEntity(thisScript)
end tell

if myRes is not false then
	
	tell application "AppleScript Editor"
		open thisScript
		tell its document 1
			activate
			try
				set selection to character myRes
			on error e number n
				display dialog e & " : " & n
			end try
			tell application "System Events"
				tell window 1 of application process "AppleScript Editor"
					tell its window 1
						key code 124
					end tell
				end tell
			end tell
		end tell
	end tell
end if

Script Debugger 4.5


set thisScript to (choose file)

tell application "LibraryLister"
	set myRes to getPosForEntity(thisScript)
end tell


if myRes is not false then
	
	tell application "Script Debugger 4.5"
		open thisScript
		tell its window 1
			activate
			set character range of selection of (its document) to {myRes, 1}
			tell application "System Events"
				tell window 1 of application process "Script Debugger 4.5"
					tell its window 1
						key code 124
					end tell
				end tell
			end tell
			
		end tell
	end tell
end if

Smile

set thisScript to (choose file)
tell application "LibraryLister"
	set myRes to getPosForEntity(thisScript)
end tell

if myRes is not false then
	
	tell application "Smile"
		open thisScript
		set selection of window 1 to {myRes, 1}

		tell application "System Events"
			tell application process "Smile"
				tell its window 1
					key code 123
				end tell
			end tell
		end tell
		tell its window 1 to activate
	end tell
end if

Hello.

I updated the LibrarLister to be more silent when nothing is found, as it still was in a kind of debug state.

I discovered a bug and updated the documentation with it.

Bugs
You will get a mismatch if you have literals like “\t” or “\r” or “\n” in your code. That is due to osadecompile which translates the literals into the real thing. The reported position after one such character will be on less than reality, and so on for the next encountered literals. If you want and need correct positions, then you have to find alternatives to these literals. This will not be fixed.

I have updated all the handlers for listing the current file.

Hello.

I discovered that it was very naive in interpreting block comments, when I started to comment a file differently.
Apologies for that. I have updated the block comment parsing code to be more intelligent.

It is still somewhat naive:

It doesn’t detect block comment tags that are within strings, which means that if you have just as start or end block comment tag in a string between two real comments, or before or or after one, then the block comments will be perceived as unbalanced and it may lead to inaccuracies. This is the place to look if your handlers or script objects doesn’t turn up in the list of handlers.

I you have block comments in strings, your last resort is to declare a balancing string with the missing tag in, within
that same scope of code.

Hello I have written a script for listing the current file that supports all the three editors.
The script can be found here

The reason for posting it there, is for the technique used to achieve this. Other scripts like this which are on the door step, will be posted here in this thread.

Hello.

Regarding the script from the post above which can be found here
There were a launch statement missing from the "tell “LibraryLister” block, which led to the display of a run dialog when LibraryLister were started. You can just insert that statement by your self or download the updated code.

Hello.

I have updated the LibraryLister to display a list of buffers that it currently holds, and wrapped all the functionality, which runs with AppleScript Editor, ScriptDebugger 4.5 and Smile. The script will compile well on your machine, even if one or more of those editors are amiss. This means that you can access the same entity from whichever editor your are currently using. And that there is just one menu item to install.

ctrl option L is the recommended short-cut key

I use a fall back pattern in this script. Which means that every time you hit Escape in a dialog something new happens. If you really want to get out of it before having gone through all the choices then hit command period.

Usage:

First you are shown the handlers of your current file -if any. If you hit Escape at that moment, then your are given the option to choose among the open buffers the LibraryLister currently holds. If none of these suites you, then hit Escape again and choose a file you would like to get a list of entities from (handlers and script objects).

Other Updates:

I have modified the spacing of the entity list LibraryLister , so that it reflects the hierarchy better.

I ponder adding some kind of “positioning directive” for adjusting for escaped literals, but will have to use it
for a while to see wether that is necessary or not.

The other options than just moving to a position in a file, is what is up next. I wouldn’t be surprised if you will be!:smiley:

Enjoy! :smiley:

You must of course download the latest copy of the from the first post in this thread as well.


-- The Idea and implementation and any faults is totally mine. © McUsr 2010 and put in the Public Domain.
-- The usually guarrantees about nothing what so ever applies, use it at your own risk.
-- Read the documentation.
-- You are not allowed to post this code elsewhere, but may of course refer to the post at macscripter.net.
” macscripter.net/viewtopic.php?pid=131438#p131438
(*
TERMS OF USE. 
This applies only to posting code, as long as you don't post it on other websites, or displays it (the code) on your own, you are welcome to do
whatever you want to do with it without any further permission. 
Except for the following: Selling the code as is, or removing copyright statmentents and the embedded link in the code (without the http:// part) from the code. 
I don't require you to keep this whole novel, but you must keep the link which refers to where it was originally posted. And my copyright.
You must also state what you eventually have done with the original source. This obviously doesn't matter if you distribute AppleScript as read only. I do not require you to embed any properties helding copyright notice for the code when you distribute as read only.

Credit for having contributed to your product would in all cases be nice!

If you use this code as part of script of yours you are of course welcome to post that code with my code in it here at macscripter.net. If you then wish to post your code elsewhere after having uploaded it to MacScripter.net please email me and ask for permission.

The ideal situation is however that you then refer to your code by a link to MacScripter.net
The sole reason for this, is that it is so much better for all of us to have a centralized codebase which are updated, than having to roam the net to find any usable snippets. Which some of us probabaly originated in the first hand.

I'm picky about this. If I find you to have published parts of my code on any other site without previous permission, I'll do what I can to have the site remove the code, ban you, and sue you under the jurisdiction of AGDER LAGMANNSRETT of Norway. Those are the terms you silently agree too by using this code. 

The above paragraphs are also valid if you violate any of my terms.

If you use this or have advantage of this code in a professional setting, where professional setting means that you use this code to earn money by keeping yourself more productive. Or if you as an employee share the resulting script with other coworkers, enhancing the productivity of your company, then a modest donation to MacScripter.net would be appreciated.

*)
-- © McUsr 2010 and put in Public Domain see: macscripter.net/viewtopic.php?pid=131438#p131438 for reference and terms of use.
property inited : missing value
on run
	if my inited is missing value then
		nativeSupport's init()
		set my inited to true
	end if
	
	set itIsOkToListChosenFile to false
	
	set bidFrontApp to my bundleId's frontmostBundleId()
	if my nativeSupport's frontmostAppAmongstInstalled(bidFrontApp) then
		set itIsOkToListChosenFile to true
	else if frontmostAppAmongstSupported(bidFrontApp) then
		tell me
			activate
			try
				display dialog "The fronmost application is currently not supported. 
			Open the script and enter a space somewhere before saving it.
			Then run the script again."
			end try
		end tell
		
	end if
	
	-- A fall back pattern, first current file, then buffer list, then choose file to list
	if itIsOkToListChosenFile is true then
		set thisScript to my nativeSupport's dispatcher_0_(1, bidFrontApp)
		if thisScript is not false then
			tell application "LibraryLister"
				launch
				set myRes to getPosForEntity(thisScript)
			end tell
			if myRes is not false then
				my nativeSupport's dispatcher_1_(2, bidFrontApp, myRes)
			else
				tell application "LibraryLister"
					launch
					set myRes to displayBuffers()
				end tell
				if myRes is not false then
					-- open the file which is item 2 of myres goto the pos which is item 1 of myres
					tell application id bidFrontApp
						open (item 2 of myRes as alias)
					end tell
					my nativeSupport's dispatcher_1_(2, bidFrontApp, (item 1 of myRes))
				else
					tell me
						activate
						set thisScript to (choose file) -- we just die if we don't get a file.
					end tell
					tell application id bidFrontApp
						open thisScript
					end tell
					tell application "LibraryLister"
						set myRes to getPosForEntity(thisScript)
					end tell
					if myRes is not false then
						my nativeSupport's dispatcher_1_(2, bidFrontApp, myRes)
					end if
				end if
			end if
		end if
	end if
end run


-- © McUsr and Put in public domain 2010. You may use it as you will but not post it elsewhere. as stated above.
-- Find some other post of mine in code exchange and read what that implies.
script nativeSupport
	property installedAppsBundleIds : {} -- should be hard coded as well?
	property supportedAppBundleIds : {}
	-- should be hardcoded when the installer is written.
	--	property assumedDefaultApp : "com.apple.ScriptEditor2"
	--	property LSRoleId : "com.apple.applescript.script"
	property nativeHandlers : {}
	property handlerList : {}
	on setInstalledAppsBundeleIds(listOfUTId)
		set my nativeSupport's installedAppsBundleIds to listOfUTId
	end setInstalledAppsBundeleIds
	
	on frontmostAppAmongstInstalled(thisBundleId)
		-- returns true if frontmost app is among installed.
		if thisBundleId is in my nativeSupport's installedAppsBundleIds then
			return true
		else
			return false
		end if
	end frontmostAppAmongstInstalled
	
	on frontmostAppAmongstSupported(thisBundleId)
		-- returns true if frontmost app is among supported.
		if my bundleId's frontmostBundleId() is in my nativeSupport's supportedAppBundleIds then
			return true
		else
			return false
		end if
	end frontmostAppAmongstSupported
	
	
	on dispatcher_0_(functIdx, UTI)
		-- 0 because it takes 1 parameter! every handler must return a result
		global _McUsrs_nativeFuncToDispatch
		local theRes, uti_index
		set uti_index to my nativeSupport's IndexOfItem(UTI, my nativeSupport's installedAppsBundleIds)
		set _McUsrs_nativeFuncToDispatch to item uti_index of item functIdx of my nativeSupport's nativeHandlers
		set theRes to _McUsrs_nativeFuncToDispatch()
		return theRes
	end dispatcher_0_
	
	on dispatcher_1_(functIdx, UTI, andAParameter)
		-- 1 because it takes 1 parameter! every handler must return a result
		global _McUsrs_nativeFuncToDispatch
		local theRes, uti_index
		set uti_index to my nativeSupport's IndexOfItem(UTI, my nativeSupport's installedAppsBundleIds)
		set _McUsrs_nativeFuncToDispatch to item uti_index of item functIdx of my nativeSupport's nativeHandlers
		set theRes to _McUsrs_nativeFuncToDispatch(andAParameter)
		return theRes
	end dispatcher_1_
	
	on IndexOfItem(theItem, theList) -- credit to Emmanuel Levy but I modified it with the considering case statements
		considering case
			set text item delimiters to return
			set theList to return & theList & return
			set text item delimiters to {""}
			try
				-1 + (count (paragraphs of (text 1 thru (offset of (return & theItem & return) in theList) of theList)))
			on error
				0
			end try
		end considering
	end IndexOfItem
	
	on findInstalledApps()
		-- returns the installed apps on the users machine
		script o
			property l : {}
		end script
		repeat with aBundleId in my nativeSupport's supportedAppBundleIds
			try
				tell application "Finder"
					set a to name of application file id aBundleId
					set end of o's l to contents of aBundleId
				end tell
			end try
		end repeat
		return o's l
	end findInstalledApps
	
	on init()
		-- builds up our indices for the handlers first
		set my nativeSupport's supportedAppBundleIds to {"com.satimage.Smile", "com.apple.ScriptEditor2", "com.latenightsw.ScriptDebugger"}
		my nativeSupport's setInstalledAppsBundeleIds(my nativeSupport's findInstalledApps())
		set my nativeSupport's handlerList to {"fileAliasForFrontDocument", "listCurrentFile"}
		set my nativeSupport's nativeHandlers to {{my fileAliasForFrontDocument_com_satimage_Smile, my fileAliasForFrontDocument_com_apple_ScriptEditor2, my fileAliasForFrontDocument_com_latenightsw_ScriptDebugger}, {my listCurrentFile_com_satimage_Smile, my listCurrentFile_com_apple_ScriptEditor2, my listCurrentFile_com_latenightsw_ScriptDebugger}}
	end init
end script

-- © McUsr and Put in public domain 2010. You may use it as you will but not post it elsewhere. as stated above.

script bundleId
	on defaultAppBundleId(LSHandlerContentTypeOrTagClass) -- Made considerably shorter and faster by Nigel Garvey
		-- Not LSHandlerContentTag check out defaults read com.apple.LaunchServices |more
		-- Doesn't work awfully well with public.filename-extension!
		try
			set LSHandlerRoleAll to (do shell script "/usr/bin/defaults read com.apple.LaunchServices | /usr/bin/grep -A 2 " & LSHandlerContentTypeOrTagClass)
			set {tids, text item delimiters} to {text item delimiters, "\""}
			set LSHandlerRoleAll to text item -2 of LSHandlerRoleAll
			set text item delimiters to tids
			return LSHandlerRoleAll
		on error
			return "" -- The app is most probably the assumed one.
		end try
	end defaultAppBundleId
	
	on frontmostBundleId()
		return id of application (path to frontmost application as Unicode text)
	end frontmostBundleId
end script



on fileAliasForFrontDocument_com_satimage_Smile()
	local thisScript, s
	using terms from application "Smile"
		set s to application id "com.satimage.Smile"
		tell s
			if (count its script windows) is greater than 0 then
				set thisScript to path name of its front window as alias
				return thisScript
			else
				return false
			end if
		end tell
	end using terms from
end fileAliasForFrontDocument_com_satimage_Smile


on fileAliasForFrontDocument_com_latenightsw_ScriptDebugger()
	local thisScript, s
	using terms from application "Script Debugger 4.5"
		set s to application id "com.latenightsw.ScriptDebugger"
		tell s
			if (count its documents) is greater than 0 then
				set thisScript to file spec of its document of its script window 1 as alias
				return thisScript
			else
				return false
			end if
		end tell
	end using terms from
end fileAliasForFrontDocument_com_latenightsw_ScriptDebugger

on fileAliasForFrontDocument_com_apple_ScriptEditor2()
	
	local thisScript
	tell application id "com.apple.ScriptEditor2"
		if (count its documents) is greater than 0 then
			set thisScript to POSIX file (path of its front document) as alias -- as Unicode text
			return thisScript
		else
			return false
		end if
	end tell
end fileAliasForFrontDocument_com_apple_ScriptEditor2

on listCurrentFile_com_satimage_Smile(thePosition)
	if thePosition is not false then
		using terms from application "Smile"
			set s to application id "com.satimage.Smile"
			tell s
				tell its window 1
					activate
					set its selection to {thePosition, 1}
					tell application "System Events"
						tell application process id "com.satimage.Smile"
							tell its window 1
								key code 124
								key code 123
							end tell
						end tell
					end tell
				end tell
			end tell
		end using terms from
	end if
	return null
end listCurrentFile_com_satimage_Smile

on listCurrentFile_com_latenightsw_ScriptDebugger(thePosition)
	local s
	if thePosition is not false then
		using terms from application "Script Debugger 4.5"
			set s to application id "com.latenightsw.ScriptDebugger"
			tell s
				tell its window 1
					activate
					set character range of selection of (its document) to {thePosition, 1}
					tell application "System Events"
						tell application process id "com.latenightsw.ScriptDebugger"
							tell its window 1
								key code 124
							end tell
						end tell
					end tell
				end tell
			end tell
		end using terms from
	end if
	return null
end listCurrentFile_com_latenightsw_ScriptDebugger


on listCurrentFile_com_apple_ScriptEditor2(thePosition)
	local s
	if thePosition is not false then
		
		tell application id "com.apple.ScriptEditor2"
			tell its window 1 to activate
			tell its document 1
				try
					set selection to insertion point thePosition
				on error e number n
					tell me
						activate
						display dialog e & " : " & n
					end tell
				end try
				tell application "System Events"
					tell window 1 of application process id "com.apple.ScriptEditor2"
						tell its window 1
							key code 124
						end tell
					end tell
				end tell
			end tell
		end tell
	end if
	return null
end listCurrentFile_com_apple_ScriptEditor2


Hello this is the updated version of the LibraryLister with a bug removed from its idle handler. The problem was that
a date wasn’t coerced properly when the script was run as an applet. This is fixed by a correct coercion.

The script has now moved from the first post to here.



-- The Idea and implementation and any faults is totally mine. © McUsr 2010 and put in the Public Domain.
-- The usually guarrantees about nothing what so ever applies, use it at your own risk.
-- Read the documentation.
-- You are not allowed to post this code elsewhere, but may of course refer to the post at macscripter.net.
-- macscripter.net/viewtopic.php?id=33712
(*
TERMS OF USE. 
This applies only to posting code, as long as you don't post it on other websites, or displays it (the code) on your own, you are welcome to do
whatever you want to do with it without any further permission. 
Except for the following: Selling the code as is, or removing copyright statmentents and the embedded link in the code (without the http:// part) from the code. 
I don't require you to keep this whole novel, but you must keep the link which refers to where it was originally posted. And my copyright.
You must also state what you eventually have done with the original source. This obviously doesn't matter if you distribute AppleScript as read only. I do not require you to embed any properties helding copyright notice for the code when you distribute as read only.

Credit for having contributed to your product would in all cases be nice!

If you use this code as part of script of yours you are of course welcome to post that code with my code in it here at macscripter.net. If you then wish to post your code elsewhere after having uploaded it to MacScripter.net please email me and ask for permission.

The ideal situation is however that you then refer to your code by a link to MacScripter.net
The sole reason for this, is that it is so much better for all of us to have a centralized codebase which are updated, than having to roam the net to find any usable snippets. Which some of us probabaly originated in the first hand.

I'm picky about this. If I find you to have published parts of my code on any other site without previous permission, I'll do what I can to have the site remove the code, ban you, and sue you under the jurisdiction of AGDER LAGMANNSRETT of Norway. Those are the terms you silently agree too by using this code. 

The above paragraphs are also valid if you violate any of my terms.

If you use this or have advantage of this code in a professional setting, where professional setting means that you use this code to earn money by keeping yourself more productive. Or if you as an employee share the resulting script with other coworkers, enhancing the productivity of your company, then a modest donation to MacScripter.net would be appreciated.

*)
-- © McUsr 2010 and put in Public Domain see: macscripter.net/viewtopic.php?id=33712 for reference and terms of use.
property bufferList : {} -- will contain filename and buffer and timestamp
property fileList : {}
property bufIndex : 0
property McUsr : "© 2010 and put in public domain - Script Library Lister and put in Public Domain"
property testing : 0
on run
end run

on displayBuffers()
	-- Displays the buffers currently held in the server. This functionality is implemented as a "Fall back" pattern.
	-- i.e this function is called when you hit escape upon listing the current file. if you then it escape you will be taken to the file choose dialog.
	-- you can just press cmd period at any time to abort the script. whatever stage the script is in.
	-- returns false or a position to jump to and the file name.
	
	
	local fileCount, displayList, listIdx, listToShow, defaultPos, theItem, theRecordNumber
	set displayList to {}
	set fileCount to (count my fileList)
	if fileCount is 0 then return false
	repeat with i from 1 to fileCount
		copy item 1 of item i of my fileList to end of displayList
	end repeat
	set listIdx to getBuffer(displayList)
	if listIdx is false then return false
	
	set item 3 of (item (listIdx) of my fileList) to (current date)
	set listToShow to (item 3 of item (listIdx) of my bufferList) -- preplist
	set defaultPos to item 4 of item (listIdx) of my bufferList
	try
		
		tell me
			activate
			try
				set theItem to choose from list listToShow default items (item defaultPos of listToShow) with prompt (quoted form of POSIX path of (item listIdx of displayList))
			end try
		end tell
		if theItem is not false then
			set theRecordNumber to (text 1 thru 2 of (theItem as text)) as number
			set defaultPos to theRecordNumber as integer
			set item 4 of item (listIdx) of my bufferList to defaultPos
			return {matchPos of item theRecordNumber of item 2 of item (listIdx) of my bufferList, item listIdx of displayList}
		else
			return false
		end if
	on error e number n
		if true is false then
			tell me
				activate
				display dialog "LL: displayBuffers Error : " & e & " : " & n
			end tell
		end if
		return false
	end try
end displayBuffers

on getBuffer(hfsTextList)
	-- should return index number or false.
	local tids, theNames, theDisks, chosenBuffer, idx
	script o
		property LF : (run script "\"\\n\"") as Unicode text -- Nigel Garvey
	end script
	set {tids, text item delimiters} to {text item delimiters, o's LF}
	set {theNames, text item delimiters} to {every item of hfsTextList as Unicode text, ""}
	set {theNames, theDisks} to {every text item of theNames, list disks}
	repeat with aDisk in theDisks
		set {theNames, text item delimiters} to {theNames as Unicode text, aDisk}
		set {theNames, text item delimiters} to {text items of theNames, ""}
	end repeat
	set {theNames, text item delimiters} to {theNames as Unicode text, ":"}
	set {theNames, text item delimiters} to {text items of theNames, "/"}
	set theNames to text items of theNames as Unicode text
	set {theNames, text item delimiters} to {theNames as Unicode text, o's LF}
	set {theNames, text item delimiters} to {text items of theNames, tids}
	tell me
		activate
		set chosenBuffer to (choose from list theNames default items item 1 of theNames with prompt "Choose the library you want to list:")
	end tell
	
	if chosenBuffer is false then return false
	set idx to indexOfItem(chosenBuffer, theNames)
	return idx
end getBuffer


on getPosForEntity(fileAlias)
	-- This is the message for the server to show up with a list dialog and 
	-- whence the libray is not loaded from before. - the files are organized on file names.
	try
		set listToShow to retrieveSourceText(fileAlias)
		set defaultPos to item 4 of item (my bufIndex) of my bufferList
		tell me
			activate
			try
				set theItem to choose from list listToShow default items (item defaultPos of listToShow) with prompt (quoted form of POSIX path of (fileAlias))
			end try
		end tell
		if theItem is not false then
			set theRecordNumber to (text 1 thru 2 of (theItem as text)) as number
			set defaultPos to theRecordNumber as integer
			set item 4 of item (my bufIndex) of my bufferList to defaultPos
			return matchPos of item theRecordNumber of item 2 of item (my bufIndex) of my bufferList
		else
			return false
		end if
	on error e number n
		if true is false then
			tell me
				activate
				display dialog "LL: getPosForEntity Error : " & e & " : " & n
			end tell
		end if
		return false
	end try
end getPosForEntity


on retrieveSourceText(fileAlias)
	-- Gives the list of choices back, and retrieves source and updates any "dirty buffers"
	local txtOfLibraryScript, theList, prepList
	try
		if not my bufferList is {} then
			
			set bufIndex to indexOfItem(fileAlias as text, my fileList)
			if bufIndex is 0 then -- make a newe buffer
				set txtOfLibraryScript to getLibraryText(fileAlias)
				set theList to LLister(txtOfLibraryScript, fileAlias as text)
				set prepList to preparateSimpleList(theList)
				
				tell application "Finder" to set fileModDate to (modification date of fileAlias)
				set end of my fileList to {fileAlias as Unicode text, fileModDate, (current date)}
				set end of my bufferList to {txtOfLibraryScript, theList, prepList, 1}
				set bufIndex to (count fileList)
				return prepList
			else
				set bufIndex to bufIndex mod 3 + bufIndex div 3
				tell application "Finder" to set fileModDate to (modification date of fileAlias)
				if fileModDate is greater than contents of item 2 of (item (bufIndex) of fileList) then -- update contents.
					-- I would have gotten the previous handler here.
					set txtOfLibraryScript to getLibraryText(fileAlias) -- rereads in the changed file
					set theList to LLister(txtOfLibraryScript, fileAlias as text)
					set prepList to preparateSimpleList(theList)
					set item (bufIndex) of my fileList to {fileAlias as Unicode text, fileModDate, (current date)}
					set prevChoice to item 4 of item (bufIndex) of my bufferList
					-- checks for if the previous position exists, should really have been the same handler but
					-- not now - later!
					set bufCount to (count bufferList)
					if prevChoice is less than bufCount then
						set item (bufIndex) of my bufferList to {txtOfLibraryScript, theList, prepList, prevChoice}
					else
						set item (bufIndex) of my bufferList to {txtOfLibraryScript, theList, prepList, bufCount}
					end if
					return prepList
				else -- just update expiry date.
					set item 3 of (item (bufIndex) of my fileList) to (current date)
					return (item 3 of item (bufIndex) of my bufferList) -- preplist
				end if
			end if
		else -- make new buffer.
			set txtOfLibraryScript to getLibraryText(fileAlias)
			set theList to LLister(txtOfLibraryScript, fileAlias as text)
			set prepList to preparateSimpleList(theList)
			tell application "Finder"
				set fileModDate to modification date of file fileAlias
			end tell
			set end of my fileList to {fileAlias as Unicode text, fileModDate, (current date)}
			set end of my bufferList to {txtOfLibraryScript, theList, prepList, 1}
			set bufIndex to 1
			return prepList
		end if
	on error e number n
		if false is true then
			tell me
				activate
				display alert "retrieveSourceText :" & e & " : " & n
			end tell
		end if
		error number -128
	end try
end retrieveSourceText

on idle
	-- empties buffers on two hours expiry
	local hadExpired, fileListCount
	set fileListCount to (count my fileList)
	set hadExpired to false
	try
		repeat with i from 1 to fileListCount
			if (current date) - (contents of item 3 of item i of my fileList as date) is greater than 7200 then -- 2 hours
				set {item i of my fileList, item i of my bufferList} to {missing value, missing value}
				set hadExpired to true
			end if
		end repeat
		if hadExpired is true then
			set my fileList to my fileList's lists
			set my bufferList to my bufferList's text
		end if
	on error e number n
		tell me
			activate
			display alert "LL's Idle handler : error " & e & " : " & n
		end tell
	end try
	if hadExpired is false and fileListCount is 0 then
		tell me to quit
	end if
	
	return 900 -- 15 minutes
end idle

on indexOfItem(theItem, itemsList) -- credit to Emmanuel Levy but I modified it with the considering case statements
	local rs
	considering case
		set text item delimiters to return
		set itemsList to return & itemsList & return
		set text item delimiters to {""}
		try
			set rs to -1 + (count (paragraphs of (text 1 thru (offset of (return & theItem & return) in itemsList) of itemsList)))
		on error
			return 0
		end try
		rs
	end considering
end indexOfItem

on LLister(txtOfLibraryScript, hfSfileNameAsText)
	script o
		property McUsr : "11 Modified for server usage: From LibraryLister 7.0 Non optimized, which works best in the most cases"
		property MAXLEVEL : 4
		
	end script
	
	local txtOfLibraryScript
	local commentlist, level1ScriptObjects, level1Handlers, level2Handlers, scriptObjectEntities, washingCandidates, MergedList, childList
	local callCount, startPattern, tabString
	
	set {commentlist, level1ScriptObjects, level1Handlers, level2Handlers, scriptObjectEntities, washingCandidates, MergedList} to {{}, {}, {}, {}, {}, {}, {}}
	set {callCount, tabString} to {0, ""}
	
	getBlockCommentPositions(txtOfLibraryScript, commentlist)
	-- Collects level 1 script objects.
	(*	set AppleScript's text item delimiters to ","
	log "commentlist " & commentlist
	set AppleScript's text item delimiters to ""
	return
*)
	set level1ScriptObjects to makeEntityList(("^" & tabString & "(script|using terms from)[ ](.*$)"), "\\2", txtOfLibraryScript)
	
	set level1ScriptObjects to washOutBlockCommentedEntities(level1ScriptObjects, commentlist)
	
	-- collects level 1 handlers.
	set level1Handlers to makeEntityList(("^" & tabString & "(on|to)[ ](.*$)"), "\\2", txtOfLibraryScript)
	
	set level1Handlers to washOutBlockCommentedEntities(level1Handlers, commentlist)
	
	set level1Handlers to washOutOnErrorStatements(level1Handlers)
	
	if level1ScriptObjects is {} and level1Handlers is {} then
		tell me
			activate
			display alert "There were no script objects nor handlers in  in " & hfSfileNameAsText & "!"
			error number -128
		end tell
	end if
	
	set {tabString, level2Handlers} to {"\t", {}} -- uses the new value for retrieving any level 2 script objects as well.
	if level1ScriptObjects is not {} then
		-- collect any level 2 handlers.
		set level2Handlers to makeEntityList(("^" & tabString & "(on|to)[ ](.*$)"), "\\2", txtOfLibraryScript)
		set level2Handlers to washOutBlockCommentedEntities(level2Handlers, commentlist)
		set level2Handlers to washOutOnErrorStatements(level2Handlers)
		set level2Handlers to prependIndent(tabString, level2Handlers)
		-- Merge the Level2 handlers with the ScriptObjects List and create a Candidates list for washing at the same time.
		set scriptObjectEntities to mergeHandlersFindPossibleEmptyScriptObjects(level2Handlers, level1ScriptObjects, scriptObjectEntities, washingCandidates, callCount, o's MAXLEVEL)
		set level2Handlers to missing value
	end if
	
	if level1Handlers is not {} and scriptObjectEntities is not {} then
		-- Merges level1Handlers with scriptObjectEntites before adding any children.
		local HandlerFirstPos, HandlerItemNo, HandlerCount, ScriptObjectFirstPos, ScriptObjectItemNo, ScriptObjectCount
		set {HandlerFirstPos, HandlerItemNo, HandlerCount} to {matchPos of item 1 of level1Handlers, 1, (count level1Handlers)}
		set {ScriptObjectFirstPos, ScriptObjectItemNo, ScriptObjectCount} to {matchPos of item 1 of scriptObjectEntities, 1, (count scriptObjectEntities)}
		
		repeat while ((ScriptObjectItemNo ≤ ScriptObjectCount) or (HandlerItemNo ≤ HandlerCount))
			if (ScriptObjectItemNo > ScriptObjectCount) then
				set end of MergedList to item HandlerItemNo of level1Handlers
				set HandlerItemNo to HandlerItemNo + 1
			else if (HandlerItemNo > HandlerCount) then
				set end of MergedList to item ScriptObjectItemNo of scriptObjectEntities
				set ScriptObjectItemNo to ScriptObjectItemNo + 1
			else if (matchPos of contents of item HandlerItemNo of level1Handlers < matchPos of contents of item ScriptObjectItemNo of scriptObjectEntities) then
				set end of MergedList to item HandlerItemNo of level1Handlers
				set HandlerItemNo to HandlerItemNo + 1
			else
				set end of MergedList to item ScriptObjectItemNo of scriptObjectEntities
				set ScriptObjectItemNo to ScriptObjectItemNo + 1
			end if
		end repeat
		
	else if level1Handlers is {} then
		set MergedList to scriptObjectEntities
	else -- had to have  handlers, -- we had to to get here.
		set MergedList to level1Handlers
	end if
	-- we are now getting at level 2 script objects, i.e at the same level as the level2 handlers.
	set childList to getScriptObjectEntities(tabString, txtOfLibraryScript, commentlist, callCount, o's MAXLEVEL)
	
	-- following handlers check for an empty child list
	if washingCandidates ≠ {} then
		set MergedList to washParentListForEmptyObjects(MergedList, childList, level1ScriptObjects, washingCandidates)
	end if
	set {level1ScriptObjects, washingCandidates} to {missing value, missing value}
	set MergedList to mergeCleanLists(MergedList, childList)
	set childList to missing value
	return MergedList -- this is a very bad idea maybe. maybe not.
	-- extracts the result for viewing
end LLister

on preparateSimpleList(theList)
	script o
		property l : theList
		property m : {}
	end script
	local displayList
	set displayList to {}
	
	repeat with i from 1 to (count theList)
		set end of o's m to (text -2 thru -1 of ("00" & i)) & "    " & matchResult of item i of o's l
	end repeat
	return o's m
end preparateSimpleList


on getLibraryText(fileAlias) -- Thanks to oldmanegan
	-- reworked since 7.0 since will use. returns text of Script library upon success
	-- factored out for the case that we will maintain buffers.
	local theSourceText, qfPoxPath
	set qfPoxPath to quoted form of POSIX path of (fileAlias)
	try
		fileAlias as alias
	on error e number n
		set bad to true
	end try
	try
		set theSourceText to do shell script "/usr/bin/osadecompile " & qfPoxPath & "| /usr/bin/tr -d '\\000'"
	on error e number n
		tell me
			activate
			display alert "getLibraryText" & e & " : " & n
		end tell
		error number -128
	end try
	if theSourceText is "" then
		tell me
			activate
			display alert "getLibraryText: The Script " & qfPoxPath & " is empty, or left in debugging state"
		end tell
		error number -128
	end if
	return theSourceText
end getLibraryText




on getScriptObjectEntities(tabIndent, theTextToPeruse, commentlist, callCount, MAXLEVEL)
	-- Collects a script object with its contents. returns a single indented list of items.
	-- Emtpy script objects washed away.
	-- CONTEXT: The first level of both handlers and script objects and the second level of handlers is already parsed
	local tabCount, originalIndent, ScriptObjectList, HandlerList
	set {tabCount, originalIndent, ScriptObjectList, callCount} to {1, tabIndent, {}, callCount + 1}
	-- Collects script objects.
	set ScriptObjectList to makeEntityList(("^" & tabIndent & "(script|using terms from)[ ](.*$)"), "\\2", theTextToPeruse)
	set ScriptObjectList to washOutBlockCommentedEntities(ScriptObjectList, commentlist)
	set ScriptObjectList to prependIndent(tabIndent, ScriptObjectList)
	
	if ScriptObjectList is not {} then -- END CONDITON FOR RECURSION
		-- Finds any handlers in the script objects so far.
		set {tabIndent, HandlerList} to {(tabIndent & "\t"), {}}
		set HandlerList to makeEntityList(("^" & tabIndent & "(on|to)[ ](.*$)"), "\\2", theTextToPeruse)
		set HandlerList to washOutBlockCommentedEntities(HandlerList, commentlist)
		set HandlerList to washOutOnErrorStatements(HandlerList)
		set HandlerList to prependIndent(tabIndent, HandlerList)
		if HandlerList is {} and callCount is MAXLEVEL then return {}
	else
		return {}
	end if
	
	-- Merges the eventual outcome of previous gathering into single lists, marks possible empty script objects for washing.
	local MergedList, washingCandidates
	set {MergedList, washingCandidates} to {{}, {}}
	
	set MergedList to mergeHandlersFindPossibleEmptyScriptObjects(HandlerList, ScriptObjectList, MergedList, washingCandidates, callCount, MAXLEVEL)
	if HandlerList is {} then
		set washingCandidates to indexByNextAList(ScriptObjectList)
	end if
	
	set HandlerList to missing value
	
	if callCount is MAXLEVEL then
		-- washes out any candidates from findings in mergeHandlersFindPossibleEmptyScriptObjects
		set MergedList to washMergeListForEmptyScriptObjects(MergedList, washingCandidates)
		return MergedList
	else
		-- Washes away empty script objects with our aquired facts.
		set tabIndent to originalIndent & "\t"
		set childList to getScriptObjectEntities(tabIndent, theTextToPeruse, commentlist, callCount, MAXLEVEL)
		if childList is not {} then
			-- following handlers check for an empty child list
			set MergedList to washParentListForEmptyObjects(MergedList, childList, ScriptObjectList, washingCandidates)
		else
			-- just removes any items of the washlist one bye one.
			set MergedList to washMergeListForEmptyScriptObjects(MergedList, washingCandidates)
		end if
		set {ScriptObjectList, washingCandidates} to {missing value, missing value}
		set MergedList to mergeCleanLists(MergedList, childList)
		set childList to missing value
		return MergedList
	end if
end getScriptObjectEntities


on mergeHandlersFindPossibleEmptyScriptObjects(HandlerList, ScriptObjectList, MergedList, washingCandidates, callCount, MAXLEVEL)
	-- returns a list with merged handlers also tags any script objects empty so far.
	local HandlerFirstPos, HandlerItemNo, HandlerCount, ScriptObjectFirstPos, ScriptObjectItemNo, ScriptObjectCount, lastWasScriptObject
	if HandlerList is not {} then
		
		set {HandlerFirstPos, HandlerItemNo, HandlerCount} to {matchPos of item 1 of HandlerList, 1, (count HandlerList)}
		set {ScriptObjectFirstPos, ScriptObjectItemNo, ScriptObjectCount} to {matchPos of item 1 of ScriptObjectList, 2, (count ScriptObjectList)}
		set {MergedList, end of MergedList, lastWasScriptObject} to {{}, item 1 of ScriptObjectList, true}
		
		repeat while ((ScriptObjectItemNo ≤ ScriptObjectCount) or (HandlerItemNo ≤ HandlerCount))
			if (ScriptObjectItemNo > ScriptObjectCount) then
				
				
				set lastWasScriptObject to false -- because: there isn't any other script object to add at this moment.
				set end of MergedList to item HandlerItemNo of HandlerList
				set HandlerItemNo to HandlerItemNo + 1
				
			else if HandlerItemNo > HandlerCount then
				
				if lastWasScriptObject is true then
					set end of washingCandidates to {ScriptObjectItemNo, item -1 of MergedList}
					set lastWasScriptObject to false
				else
					set end of MergedList to item ScriptObjectItemNo of ScriptObjectList
					
					set end of washingCandidates to {(ScriptObjectItemNo + 1), item ScriptObjectItemNo of ScriptObjectList}
					
					set ScriptObjectItemNo to ScriptObjectItemNo + 1
					
				end if
				
			else if (matchPos of contents of item HandlerItemNo of HandlerList < matchPos of contents of item ScriptObjectItemNo of ScriptObjectList) then
				set lastWasScriptObject to false
				set end of MergedList to item HandlerItemNo of HandlerList
				set HandlerItemNo to HandlerItemNo + 1
				
			else -- Script object has a lower position value
				
				if lastWasScriptObject is false then
					set end of MergedList to item ScriptObjectItemNo of ScriptObjectList
					
				else -- two script objects in a row
					
					set end of washingCandidates to {ScriptObjectItemNo, item -1 of MergedList}
					set end of MergedList to item ScriptObjectItemNo of ScriptObjectList
				end if
				set ScriptObjectItemNo to ScriptObjectItemNo + 1
				set lastWasScriptObject to true
			end if
		end repeat
		if lastWasScriptObject is true then set end of washingCandidates to {ScriptObjectItemNo, item -1 of MergedList}
		
		set HandlerList to missing value
	else
		set MergedList to ScriptObjectList
	end if
	return MergedList
end mergeHandlersFindPossibleEmptyScriptObjects


on mergeCleanLists(parentList, childList)
	-- Merges two lists, by order of matchpos, returns result
	-- the ParentList is higher up in the hierarchy, therefore contains preceding elements.
	if not childList is {} then -- superfluos but
		local resultList, parentItemNo, parentCount, childItemNo, childCount
		set {parentItemNo, parentCount, childItemNo, childCount} to {2, (count parentList), 1, (count childList)}
		set {resultList, end of resultList} to {{}, item 1 of parentList}
		-- Safely assume that first item in merg list has lower pos than first in child list
		
		repeat while ((parentItemNo ≤ parentCount) or (childItemNo ≤ childCount))
			if (parentItemNo > parentCount) then
				
				set end of resultList to item childItemNo of childList
				set childItemNo to childItemNo + 1
				
			else if (childItemNo > childCount) then
				
				set end of resultList to item parentItemNo of parentList
				set parentItemNo to parentItemNo + 1
			else if (matchPos of contents of item childItemNo of childList < matchPos of contents of item parentItemNo of parentList) then
				
				set end of resultList to item childItemNo of childList
				set childItemNo to childItemNo + 1
				
			else
				
				set end of resultList to item parentItemNo of parentList
				set parentItemNo to parentItemNo + 1
				
			end if
		end repeat
		return resultList
	else
		return parentList
	end if
end mergeCleanLists


on washParentListForEmptyObjects(parentList, childList, origScrObjList, washList)
	-- compares elements in parent list with child list and washlist.
	-- draws a conclusion wether parent element is really empty, then removes it. 
	local parentItemNo, parentCount, childItemNo, washItemNo, washCount, washFirstPos, washLastPos, foundLaterChild, curChildPos
	set {parentItemNo, parentCount, childItemNo, childCount, washItemNo, washCount} to {1, (count parentList), 1, (count childList), 1, (count washList)}
	
	if washList ≠ {} and childList ≠ {} then
		
		set washFirstPos to matchPos of item 2 of item washItemNo of washList
		set washLastPos to matchPos of item (item 1 of item washItemNo of washList) of origScrObjList
		
		repeat while washItemNo ≤ washCount
			
			set foundLaterChild to false
			
			repeat with i from childItemNo to childCount
				
				set curChildPos to matchPos of item i of childList
				if curChildPos > washFirstPos and curChildPos < washLastPos then
					set washItemNo to washItemNo + 1
					set childItemNo to childItemNo + 1
					set foundLaterChild to true
					exit repeat -- found sibling keeps this candidate
					
				else if curChildPos > washLastPos then -- must be less than, positions are unique
					set foundLaterChild to true -- we bypassed the candidate
					
					repeat with j from parentItemNo to parentCount
						if matchPos of item j of parentList = washFirstPos then
							set item j of parentList to missing value
							set mergeItemNo to j + 1
							exit repeat
						end if
					end repeat
					set washItemNo to washItemNo + 1
					set foundLaterChild to true
					exit repeat
				end if
			end repeat
			
			if foundLaterChild is false then
				-- all there is to delete every member of washingList from parentList
				repeat with i from washItemNo to washCount
					repeat with j from parentItemNo to contents of parentCount
						if matchPos of item j of parentList = washFirstPos then
							set item j of parentList to missing value
							set parentItemNo to j + 1
							exit repeat
						end if
						-- set washFirstPos to matchPos of item 2 of item (i + 1) of washList
						if i < washCount then
							set washFirstPos to matchPos of item 2 of item (i + 1) of washList
						else
							exit repeat
						end if
					end repeat
				end repeat
				exit repeat -- done WASHING
			else
				
				set washFirstPos to matchPos of item 2 of item washItemNo of washList
				set washLastPos to matchPos of item (item 1 of item washItemNo of washList) of origScrObjList
				
			end if
			
		end repeat
		set parentList to parentList's records
		-- else -just return the parentList
	end if
	return parentList
end washParentListForEmptyObjects

on washMergeListForEmptyScriptObjects(mergeList, washList)
	-- cleans a list for empty script objects,when there were no new children.
	local mergeItemNo, washItemNo, washCount, washFirstPos
	set {mergeItemNo, mergeCount, washItemNo, washCount} to {1, (count mergeList), 1, (count washList)}
	
	if washList ≠ {} then
		
		repeat with i from washItemNo to washCount
			
			set washFirstPos to matchPos of item 2 of item i of washList
			
			repeat with j from mergeItemNo to mergeCount
				if matchPos of item j of mergeList = washFirstPos then
					set item j of mergeList to missing value
					set mergeItemNo to j + 1
					exit repeat
				end if
			end repeat
		end repeat
		-- else -- nothing to merge nor wash 
		set mergeList to mergeList's records
	else
		return mergeList
	end if
end washMergeListForEmptyScriptObjects


on washOutBlockCommentedEntities(entityList, blockCommentList)
	-- removes any entity that is within a block comment.
	script o
		property l : entityList
	end script
	if not entityList is {} then
		repeat with i from 1 to (count entityList)
			if withinABlockComment(matchPos of (contents of item i of o's l), blockCommentList) then
				set item i of o's l to missing value
			end if
		end repeat
		set entityList to o's l's records
	end if
	return entityList
end washOutBlockCommentedEntities

on washOutOnErrorStatements(HandlerList)
	-- removes the "on error" statements.
	script o
		property l : HandlerList
	end script
	if not HandlerList is {} then
		repeat with i from 1 to (count HandlerList)
			if matchResult of (contents of item i of o's l) is "error" or matchResult of (contents of item i of o's l) starts with "error " then
				set item i of o's l to missing value
			end if
		end repeat
		set HandlerList to o's l's records
	end if
	return HandlerList
end washOutOnErrorStatements

on makeEntityList(seachString, searchItemNr, theTextToPeruse)
	-- Harvests out a list of entities of type specified by parameters.
	script o
		property l : theTextToPeruse
	end script
	local theRes
	set theRes to find text seachString in o's l using searchItemNr starting at 0 with regexp and all occurrences
	return theRes
end makeEntityList

on prependIndent(tabIndent, HandlerList)
	-- idents the element after we have washed out error statments for handlers
	-- anytime for script objects
	script o
		property l : HandlerList
	end script
	repeat with i from 1 to (count HandlerList)
		set matchResult of (item i of o's l) to tabIndent & (matchResult of (contents of item i of o's l))
	end repeat
	return o's l
end prependIndent

-- tells us if a pos of a particular handler is witihin a block comment.
on withinABlockComment(aPos, listOfBlockPos)
	script o
		property l : listOfBlockPos
	end script
	repeat with i from 1 to (count listOfBlockPos)
		if item 1 of item i of o's l < aPos and item 2 of item i of o's l > aPos then return true
	end repeat
	return false
end withinABlockComment

on getBlockCommentPositions(theTextToPeruse, listOfBlockPos)
	-- creates a list with start and end positons of  block comments
	script o
		property l : theTextToPeruse
		property m : listOfBlockPos
	end script
	local doneProcessing, frompos, openingPattern, closingPattern, openingPos, notFound, nextOpeningPos, closingPos
	set {frompos, openingPattern, closingPattern} to {0, "([(][*])", "([*][)])"}
	repeat
		try
			set openingPos to matchPos of (find text openingPattern in o's l using "\\0" starting at frompos with regexp)
			-- opening tag
			set frompos to openingPos + 3
			
			repeat
				set notFound to false
				try
					set nextOpeningPos to matchPos of (find text openingPattern in o's l using "\\0" starting at frompos with regexp)
				on error
					set notFound to true
				end try
				try
					set closingPos to matchPos of (find text closingPattern in o's l using "\\0" starting at frompos with regexp)
				on error e number n
					tell me
						activate
						display alert "Error finding closing comment, malformed or emebedded start comment between hyphens."
						error number -128
					end tell
				end try
				
				if notFound is true then
					exit repeat
				else if nextOpeningPos < closingPos then
					set frompos to closingPos + 3
				else
					exit repeat
				end if
			end repeat
			-- copy {openingPos, closingPos} to end of o's m
			set end of o's m to {openingPos, closingPos}
		on error e number n
			if n is -128 then
				error number -128 -- cascade
			else
				exit repeat
			end if
		end try
	end repeat
	return listOfBlockPos
end getBlockCommentPositions

on indexByNextAList(listToIndex)
	-- returns a list of lists, with item in list preceeded by its index+1.
	script o
		property l : listToIndex
	end script
	local newList
	set newList to {}
	repeat with i from 1 to (count listToIndex)
		set end of newList to {(i + 1), item i of o's l}
	end repeat
	return newList
end indexByNextAList

Hello.
I have updated the code in the post above with the hopefully solution to the talkativeness of the LibraryLister when it is out of buffers, (when it doesn’t contain any data).
This was due to one problem with the idle handler which I hope I have solved now, at least it has been silent for hours at my place! :slight_smile:

The problem seems to have been some kind of deadlock situation, in that it reaches an error handler before a value have been set, I have now added a test outside of that code to prevent it.

The applied solution has worked well with the ScriptLibraryServer for days.