• 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
Run Perl Source Text Directly from AppleScript – List AppleScript Library Handlers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Run Perl Source Text Directly from AppleScript – List AppleScript Library Handlers


  • Subject: Run Perl Source Text Directly from AppleScript – List AppleScript Library Handlers
  • From: Christopher Stone <email@hidden>
  • Date: Sun, 12 Mar 2017 22:23:40 -0500

Hey Folks,

This is several years old, but I improved it a bit based on recent learning.

Most notably I added the source ~/.profile command and tweaked the Perl code slightly.

Appropriately comment-out or uncomment the Print complete source or Produce a list of handler calls sections to get the result(s) you want.

We have some good methods for doing this job with AppleScriptObjC now, so this is somewhat obsolete – but I'm posting it (probably reposting it) for three reasons:

A) To demonstrate Perl running from AppleScript without using an intermediate file.

B) To demonstrate in practical context the use of source ~/.profile.

C) To show how to extract AppleScript library text and/or handler-calls using Perl and shell commands.

This is behaving better on Sierra than when I last tested it.  In years past it would launch several apps as the libraries decompiled, and thankfully that isn't happening at present.

I did a little site-Googling to see if I could find the ASObjC methods, and I only found the one that uses Script Debugger's RTF recovery files instead of osadecompile.

I'll post a solution that does this same thing with ASObjC tomorrow sometime.

Enjoy.

--
Best Regards,
Chris

-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2014/02/22 22:14
# dMod: 2017/03/12 21:23
# Appl: AppleScript & Perl
# Task: Run a Perl text script directly from AppleScript.
#     : Produce all library text OR only a list of handler-calls.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Run, @Perl, @Text, @Script, @Directly, @Library, @Source, @Handler, @Calls
# Vers: 0.3
-------------------------------------------------------------------------------------------

set _perl to "
use v5.012;

my ($exe, $scptSrc);

# The -regex <pattern> filters out undesired libraries – in this case the lib name MUST contain “Lb”.
# Remove “-regex \".+Lb.+\"” to find ALL libraries.
$exe = qq(find -E ~/Library/'Script Libraries'/ -depth 1 -regex \".+Lb.+\" -exec osadecompile {} \\\\;);

$scptSrc = `$exe`;

say \"Perl v$]\"; # print perl version number
say '';

#--------------------------------------------------------
# Print complete source.
#--------------------------------------------------------

# print $scptSrc;  #### presently disabled ####

#--------------------------------------------------------
# Produce a list of handler calls.
#--------------------------------------------------------

open my $fh, '<', \\$scptSrc or die $!;
while (<$fh>) {
    if ( m!^on (\\w.*?(?=[\\(:]))(.+)! ) {
        say \"$1$2\";
    }
}
close $fh or die $!;

#--------------------------------------------------------
"

set shCMD to "
source ~/.profile
/usr/bin/env perl -swf <<< " & quoted form of _perl

set libText to do shell script shCMD

-------------------------------------------------------------------------------------------

 _______________________________________________
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

  • Follow-Ups:
    • Re: Run Perl Source Text Directly from AppleScript – List AppleScript Library Handlers
      • From: debt <email@hidden>
  • Prev by Date: Re: Differences in output between AppleScript and Terminal
  • Next by Date: Re: Differences in output between AppleScript and Terminal
  • Previous by thread: getting info about the selected even in Calendar
  • Next by thread: Re: Run Perl Source Text Directly from AppleScript – List AppleScript Library Handlers
  • Index(es):
    • Date
    • Thread