• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Extracting Script Library Text and/or Handler Calls
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Extracting Script Library Text and/or Handler Calls


  • Subject: Re: Extracting Script Library Text and/or Handler Calls
  • From: Jean-Christophe Helary <email@hidden>
  • Date: Tue, 24 Apr 2018 13:53:23 +0900

Interesting post. Thank you !

JC

> On Apr 24, 2018, at 13:02, Christopher Stone <email@hidden>
> wrote:
>
> 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.
>


Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune


 _______________________________________________
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

References: 
 >Extracting Script Library Text and/or Handler Calls (From: Christopher Stone <email@hidden>)

  • Prev by Date: Extracting Script Library Text and/or Handler Calls
  • Next by Date: Re: Extracting Script Library Text and/or Handler Calls
  • Previous by thread: Extracting Script Library Text and/or Handler Calls
  • Next by thread: Re: Extracting Script Library Text and/or Handler Calls
  • Index(es):
    • Date
    • Thread