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 |