Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

How do you run a perl script using a custom perl build from an AppleScript?

by nysus (Parson)
on May 27, 2017 at 17:54 UTC ( [id://1191380]=perlquestion: print w/replies, xml ) Need Help??

nysus has asked for the wisdom of the Perl Monks concerning the following question:

I'm creating commands that I can execute by voice for my Mac. In order to do this, I want to create AppleScripts that call my perl script. For example, here's an AppleScript that will call a Perl script which moves files off the Desktop and into Documents folder:

do shell script "/Users/stevied/bin/clean_desktop.pl"

The Perl script works fine when run from the command line, but when executing the script from my AppleScript, the modules I use aren't found and I get this error:

Can't locate Modern/Perl.pm in @INC (you may need to install the Moder +n::Perl module) (@INC contains: /Library/Perl/5.18/darwin-thread-mult +i-2level /Library/Perl/5.18 /Network/Library/Perl/5.18/darwin-thread- +multi-2level /Network/Library/Perl/5.18 /Library/Perl/Updates/5.18.2 +/System/Library/Perl/5.18/darwin-thread-multi-2level /System/Library/ +Perl/5.18 /System/Library/Perl/Extras/5.18/darwin-thread-multi-2level + /System/Library/Perl/Extras/5.18 .) at /Users/stevied/bin/clean_desk +top.pl line 3. BEGIN failed--compilation aborted at /Users/stevied/bi +n/clean_desktop.pl line 3.

I have perlbrew installed. The current shebang line for the perl script is #! /usr/bin/env perl. I tried adding the following line to my perl script:

/Users/stevied/perl5/lib/perl5;

Running the AppleScript now yields this horrific looking error:

dyld: lazy symbol binding failed: Symbol not found: _Perl_xs_handshake Referenced from: /Users/stevied/perl5/lib/perl5/darwin-thread-multi- +2level/auto/Mac/SystemDirectory/SystemDirectory.bundle Expected in: flat namespace dyld: Symbol not found: _Perl_xs_handshake Referenced from: /Users/stevied/perl5/lib/perl5/darwin-thread-multi- +2level/auto/Mac/SystemDirectory/SystemDirectory.bundle Expected in: flat namespace

Is there anything I can do to get this working?

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re: How do you run a perl script using a custom perl build from an AppleScript?
by kevbot (Vicar) on May 27, 2017 at 20:53 UTC

    Hello nysus,

    I have encountered the same problem when creating services with the macOS Automator application. In Automator, one can create a workflow, and then place a run shell script step inside the workflow. An entry of /usr/bin/perl appears amongst the shell choices, but I don't see a way to choose a custom path. It seems that Automator uses the system perl, so I've always kept my Automator perl scripts very simple such that the system perl will work. Using an AppleScript (or other type of script) to launch the perl script might provide a work around. Hopefully someone will have a good answer to your question, and I will look into this more myself.

    Also, I noticed that you cross posted your question here. It's considered polite to mention cross-posts in order to minimize duplication of effort.

    UPDATE: Try to use absolute paths in your AppleScript like this:

    do shell script "/Users/stevied/perl5/perlbrew/perls/perl-5.22.2/bin/p +erl /Users/stevied/bin/clean_desktop.pl"
    This seemed to work for me in Automator. Of course, you may need to change perl-5.22.2 to the version of perl that you have installed.

      Nice, that did the trick. Thank you!

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

Re: How do you run a perl script using a custom perl build from an AppleScript?
by huck (Prior) on May 27, 2017 at 21:56 UTC
Re: How do you run a perl script using a custom perl build from an AppleScript?
by duelafn (Parson) on May 27, 2017 at 21:29 UTC

    Some things I would try (I don't use a Mac so can't test):

    1. Spawn bash explicitly (the default shell might not be getting all your environment variables):

    # Not sure how quoting should work here, so fix if needed do shell script "bash -c /Users/stevied/bin/clean_desktop.pl"

    2. Create a wrapper (e.g., clean_desktop.sh) which force-sets up perlbrew:

    #!/bin/bash perlbrew use perl-5.16.0 # or whatever version/folder you are using /Users/stevied/bin/clean_desktop.pl

    Then call the wrapper

    do shell script "/Users/stevied/bin/clean_desktop.sh"

    Good Day,
        Dean

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1191380]
Approved by Discipulus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-24 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found