Okay. Here's the basic export handlers from libraries script.
I'm dumping each handler to a text file in the Finder named with the handler-name and then the library name in curly brackets.
Warning - subsequent runs will overwrite any existing files.
This one does not support script bundles, but that's not hard to fix.
-------------------------------------------------------------------------------------------
# dCre: 2014-02-15 : 22:00
# dMod: 2014-02-15 : 23:04
# Appl: Finder
# Task: Export all handlers from all libraries (except tagged Red) to 'Handler Library' folder.
# Libs: None
# Tags: @Applescript, @Script, @Finder, @Handler, @Export
-------------------------------------------------------------------------------------------
--» MAIN
-------------------------------------------------------------------------------------------
try
set handlerLibFldr to ((path to documents folder as text) & "Scripts (Library):Handler Library:")
set libFolder to alias ((path to library folder from user domain as text) & "Script Libraries:")
tell application "Finder"
set libList to (files of libFolder whose label index is not 2 and kind is "Compiled OSA Script") as alias list
end tell
if libList ≠ {} then
if exTant(handlerLibFldr) = false then
set pxPath to quoted form of (POSIX path of handlerLibFldr)
do shell script "mkdir -p " & pxPath
end if
repeat with scriptFile in libList
set fileName to cng("^.+:(.+)", " { \\1 }", (scriptFile as text)) of me set libSrc to load resource 2001 type "TEXT" from scriptFile as «class utf8»
set handlerList to fnd("(?m)^on (
\\w+)\\(.*\\)[^\\n\\r]*$.+^end
\\1$"
, libSrc, 0, 1, 1) of me repeat with i in handlerList
set handlerText to i's contents
set handlerName
to fnd
("(?<=^on )\\w+", handlerText
, 0, 0, 1) of me writeUTF8(handlerText, (handlerLibFldr & handlerName & fileName & ".txt"))
end repeat
end repeat
tell application "Finder"
activate
if (window "Handler Library" exists) then
set index of window "Handler Library" to 1
else
open alias handlerLibFldr
set bounds of front window to {538, 44, 1382, 1196}
end if
end tell
end if
on error e number n
stdErr(e, n, true, true) of me
end try
-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
on stdErr(e, n, beepFlag, ddFlag)
set e to e & return & return & "Num: " & n
if beepFlag = true then
beep
end if
if ddFlag = true then
tell me
set dDlg to display dialog e with title "ERROR!" buttons {"Cancel", "Copy", "OK"} default button "OK"
end tell
if button returned of dDlg = "Copy" then set the clipboard to e
else
return e
end if
end stdErr
-------------------------------------------------------------------------------------------
on cng(findText, changeText, srcData)
change findText into changeText in srcData with regexp without case sensitive
end cng
-------------------------------------------------------------------------------------------
on fnd(_find, _data, _case, _all, strRslt) # Last 3 are all bool
try
find text _find in _data case sensitive _case all occurrences _all string result strRslt with regexp
on error
return false
end try
end fnd
-------------------------------------------------------------------------------------------
on exTant(_path) # Takes a path as input - HFS, Posix, or ~/Posix
try
if _path starts with "~/" then
set _path to (POSIX path of (path to home folder as text)) & text 3 thru -1 of _path
end if
if _path contains ":" then
alias _path
else if _path contains "/" then
alias POSIX file _path
end if
return true
on error
return false
end try
end exTant
-------------------------------------------------------------------------------------------
on writeUTF8(_text, _file)
try
set fRef to open for access _file with write permission
set eof of fRef to 0
write _text to fRef as «class utf8»
close access fRef
on error e number n
try
close access fRef
on error e number n
error "Error in writeUTF8() handler!" & return & return & e
end try
end try
end writeUTF8
-------------------------------------------------------------------------------------------