Extracting Script Library Text and/or Handler Calls
Extracting Script Library Text and/or Handler Calls
- Subject: Extracting Script Library Text and/or Handler Calls
- From: Christopher Stone <email@hidden>
- Date: Mon, 23 Apr 2018 23:02:58 -0500
Hey Folks,
I've posted other methods of doing this using both AppleScriptObjC and the
shell, but I was playing with do loops and wanted a familiar task to experiment
with.
Here's the result.
Keep in mind this is a shell script and must be run as such.
#!/usr/bin/env bash
# ----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2018/04/23 15:00
# dMod: 2018/04/23 15:20
# Task: List all handler calls in designated AppleScript libraries.
# Tags: @Shell, @Script, @List, @Handler, @Calls, @Designated, @AppleScript,
@Libraries
# ----------------------------------------------------------------
export LC_ALL="en_US.UTF-8" # Because the script uses utf8
characters
cd ~/'Library/Script Libraries/';
for libFile in `'ls' -d *Lb*` # Limits to libraries whose name
contains 'Lb'
do
libText+="ˆ»»» $libFile --> Startˆ" # Marker for start of library
libText+=`osadecompile $libFile` # Decompile the library
libText+="ˆ»»» $libFile --> Endˆ" # Marker for end of library
done
# Neaten up the extracted library text.
libText=$(tr 'ˆ' '\n' <<< "$libText") # To avoid interfering with library
text containing "\n"
# Comment this out to see the collated library text.
libText=$( sed -En '/^on.+|^»/{ s!^on |»!!; s!^»!--!; p; }' <<< "$libText" )
echo "$libText"
It should work with any normal library script, but it won't handle things like
Shane's BridgePlus library.
That's why the “ls” command limits libraries found to these containing “Lb” —
it's a simple filter to let me get only those libraries I want to extract
handler-calls from.
You'll need to change that for it to work on your system.
On my system it's pretty fast — ±0.8 seconds to process 6 fairly large
libraries.
The advantage of this method is that I have more control over how the text is
collated, and in this case I'm inserting markers to show the beginning and end
of each library's handlers in the overall list.
And that lets me pull a few tricks when I'm using them in various contexts.
If I just wanted to yank out the handler calls and didn't care about marking
the libraries, I'd do something more terse like this:
#!/usr/bin/env bash
# ----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2018/04/23 15:00
# dMod: 2018/04/23 15:20
# Task: Terse -- List all handler calls in designated AppleScript libraries.
# Tags: @Shell, @Script, @List, @Handler, @Calls, @Designated, @AppleScript,
@Libraries
# ----------------------------------------------------------------
export LC_ALL="en_US.UTF-8"
find ~/Library/'Script Libraries' -depth 1 -iname "*Lb*" -exec osadecompile {}
\; | sed -En 's!^on !!p'
I import all of my handler calls into Typinator for very quick and flexible
searching, and this keeps me from pulling my hair out when I don't remember
that exact handler name.
On my own system where all the script libraries are created as script bundles
with Script Debugger I use AppleScriptObjC to decode SD's backup RTF file
embedded in each library.
Why? Because it's very, very fast. :)
I'll post this script separately soon.
--
Best Regards,
Chris
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden