----------------------------------------------------------------------------------------------
# SCRIPT DEBUGGER » HANDLER PICK-LIST » PORTABLE VERSION
----------------------------------------------------------------------------------------------
# Author: Christopher Stone
# Created: 2010-11-03 : 10:42
# Modified: 2011-09-18 : 12:18
# Application: Script Debugger
# Purpose: Get all Handler Names of all Script Debugger Libs except those labeled red.
# : Present a choose-from list for the user to pick one or more and set the
# : selection of the front script document to the result.
# Dependencies: none
----------------------------------------------------------------------------------------------
set handlerCnt to 0
set sep to "----------------------------------------------------------------------"
tell application "Script Debugger 4.5"
try
set libFolder to (its script libraries folder) as alias
set handlerList to {}
tell application "Finder"
set libList to (files of libFolder whose label index is not 2) as alias list
set libNameList to (name of files of libFolder whose label index is not 2)
end tell
set libCnt to length of libList
repeat with i from 1 to (length of libList)
set libScript to quoted form of (POSIX path of (contents of item i of libList))
set libScriptName to item i of libNameList
set end of handlerList to sep
set end of handlerList to ("» " & libScriptName)
set end of handlerList to sep
set _temp to (do shell script "osadecompile " & libScript & " | egrep -i \"^on .+\\(.+\\)\" | sort -f")
set handlerCnt to handlerCnt + (length of (paragraphs of _temp))
set end of handlerList to _temp
end repeat
set end of handlerList to sep
set AppleScript's text item delimiters to return
set handlerList to handlerList as string
set AppleScript's text item delimiters to {""}
set handlerList to do shell script "tr '\\r' '\\n' <<<" & (quoted form of handlerList) & " | sed -E 's/^on //'"
set handlerList to make_list(handlerList, return) of me
set handlerList to choose from list handlerList ¬
with title "Library Handlers" with prompt ¬
("" & libCnt & " LIBRARIES" & return & ("" & handlerCnt & " HANDLERS") & return & return & ¬
"PICK ONE OR MORE HANDLERS:") with multiple selections allowed
if handlerList ≠ {} and handlerList ≠ false then
set handlerList to join_list(handlerList, return) of me
set selection of document 1 to handlerList
end if
on error errMsg number errNum
beep
display dialog "Error: " & errMsg & return & "Error Number: " & errNum
end try
end tell
------------------------------------------------------------------------------------------------
# HANDLERS
------------------------------------------------------------------------------------------------
on join_list(ListToJoin, deLimiter)
set oldTIDS to AppleScript's text item delimiters
set AppleScript's text item delimiters to deLimiter
set joinedList to ListToJoin as string
set AppleScript's text item delimiters to oldTIDS
return joinedList
end join_list
------------------------------------------------------------------------------------------------
on make_list(sourceText, deLimiter)
set oldTIDS to AppleScript's text item delimiters
set AppleScript's text item delimiters to deLimiter
set newList to text items of sourceText
set AppleScript's text item delimiters to oldTIDS
return newList
end make_list
------------------------------------------------------------------------------------------------