• 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: Differences in output between AppleScript and Terminal
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Differences in output between AppleScript and Terminal


  • Subject: Re: Differences in output between AppleScript and Terminal
  • From: debt <email@hidden>
  • Date: Sun, 12 Mar 2017 17:04:10 -0700

On Mar 11, 2017, at 11:03 PM, Christopher Stone <email@hidden> wrote:

----------------------------------------
do shell script "
source ~/.profile
/usr/bin/env perl -e 'print \"$^V\";'
"
————————————————————

Hi Chris,

As always, I appreciate your input.  Unfortunately I wasn’t able to figure out how to use the above, as it only gives me the version of the selected Perl, not the shebang line path I need.

Do shell script by design runs a completely unadulterated shell session.

I understand and agree with the premise, *however* I think we should be able to mimic the Terminal if we want to, but I haven’t found a way to do that.

Anyway, as I was waking up this morning, the answer came to me in my half-awake state, and it’s brilliant (if I may say so myself ;)  All I have to do is read the first line of the Perl script to grab the shebang line and then use that in the AppleScript.  WooHoo!  Problem solved.

set the_perl_script to (path to desktop as text) & "code:perl:test.pl"
set document_contents to (read file  the_perl_script)
set shebang to paragraph 1 of document_contents
set path_to_perl to characters 3 thru -1 of shebang as text

do shell script path_to_perl & space & quoted form of the_perl_script & space & parameters

Another plus to doing it this way is that I can use a different version of Perl in each of my scripts, if I want, and AppleScript will use the correct version for each.  And when I change/update Perl, I won’t need to update my AppleScripts.  I love automating things like this. :)

The only downside to this is that the Perl script needs to be opened and read every single time the AppleScript is run.  I really don’t like that, but at this point I don’t see another alternative.  Plus, right now I’m reading the entire file into the document_contents variable.  Is there a way to read only the first line and nothing more?

Thanks,
Marc
 _______________________________________________
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: Differences in output between AppleScript and Terminal
      • From: Yvan KOENIG <email@hidden>
    • Re: Differences in output between AppleScript and Terminal
      • From: Christopher Stone <email@hidden>
References: 
 >Differences in output between AppleScript and Terminal (From: debt <email@hidden>)
 >Re: Differences in output between AppleScript and Terminal (From: debt <email@hidden>)
 >Re: Differences in output between AppleScript and Terminal (From: Christopher Stone <email@hidden>)

  • Prev by Date: Re: Write an antislash (backslash) in a variable ?
  • Next by Date: Re: Differences in output between AppleScript and Terminal
  • Previous by thread: Re: Differences in output between AppleScript and Terminal
  • Next by thread: Re: Differences in output between AppleScript and Terminal
  • Index(es):
    • Date
    • Thread