Hello.
Prerequisites
You must have TextWrangler, and the commandline tools installed on your machine in order to use this.
What does it do?
This is a script, that lists all the handlers in an “AS 2.3” library file (2.3/2.31)
It is for those cases, when you forget either the name of a handler, or the full signature of it. That is, the handler name, and the parameters, with any prepositions, if the handler is defined like that.
It works like this:
You have a Finder window open in front of your favourite Script Editor, with the contents of the Script Libraries in it.
You select the library you wish to copy a signature from and run the script.
TextWrangler will be activated [1], and you will then be presented with a choose from list, that shows every handler in the library.
Besides the choose from list dialog you will have the source text of the script, so you can also see what it does.
NB!
When you have selected a handler signature to paste into your script, then the document gets closed, TextWrangler is hidden, and the Finder window, from where you started, is the frontmost, so it should be as easy as possible to get back on track editing your script.
This is how I like it right now, modify it to suit your needs.
Installation:
It should be installed outside any apps script menu,but on the script menu for easy access. (it may even fail if it is installed inside TextWranglers Script menu).
[1]If TextWrangler wasn’t running, then the script launches TextWrangler, and asks you to rerun the script, once you can visually see that TextWrangler has finished launching.
property scriptTitle : "LookupScriptLibraryHandler"
set libFol to (path to library folder from user domain as text) & "Script Libraries:"
tell application "Finder"
if (count Finder windows) = 0 then open (libFol as alias)
set curTarg to (target of Finder window 1 as alias as text)
if libFol is not in curTarg then
display alert scriptTitle & ":
This only works in the Script Libraries folder (with subfolders)."
set target of Finder window 1 to (libFol as alias)
return
end if
if selection is {} then
display alert "I need an item to operate on."
return
end if
if (count selection) is 1 then
display alert scriptTitle & ":
This only works with one library at a time"
return
else
set curLib to POSIX path of (selection as alias)
end if
if curLib does not end with "scptd/" and curLib does not end with "scpt" then
display alert scriptTitle & ":
This only works with \".scpt\" and \".scptd\" files."
return
end if
end tell
if not running of application id "com.barebones.textwrangler" then
tell application id "com.barebones.textwrangler" to launch
tell application (path to frontmost application as text)
display alert scriptTitle & ":
TextWrangler wasn't running, please try again, when it has finished launching."
end tell
do shell script "/usr/bin/open -b \"com.apple.finder\" "
return
end if
tell application id "sevs" to set visible of process "TextWrangler" to true
try
do shell script "/usr/bin/osadecompile " & quoted form of curLib & " |/usr/local/bin/edit "
on error
tell application (path to frontmost application as text)
display alert scriptTitle & ":
Apperently your version of edit, resides somewhere else, please run \"which edit\" in a Terminal window, and edit the path in the do shell script command accordingly before you proceed."
end tell
return
end try
try
tell application id "com.barebones.textwrangler"
set results to find "^(on|to)\\s((?!error)\\w+.*(--|\\(\\*|#)?)" options {search mode:grep, starting at top:true, wrap around:true, returning results:true} searching in {text of front text document}
set ResultList to found matches of results
set choiceList to {}
repeat with refLink in ResultList
set end of choiceList to refLink's match_string
end repeat
set handlerSignature to (choose from list choiceList with prompt "Choose a Signature:")
tell its text document 1 to close saving no
end tell
tell application id "sevs" to set visible of process "TextWrangler" to false
do shell script "/usr/bin/open -b \"com.apple.finder\" "
if handlerSignature is not false then
set handlerSignature to handlerSignature as text
set startDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"on", "to"}
set handlerSignature to text items of handlerSignature
set AppleScript's text item delimiters to startDelim
set handlerSignature to handlerSignature as text
set the clipboard to handlerSignature
end if
end try
Edit
Added scriptTitle to a display alert that I missed, when when I was adding them.