Using Perl in AppleScript Studio
Some notes about using Perl in AppleScript Studio featuring Emmanuel. M. Decarie of ScriptDigital and Tim Bumgarner of AppleScript Studio Engineering
Emmanuel. M. Decarie wrote:
If you want to use a little bit of AppleScript for manipulating the UI, you could build easily Perl app with a nice Aqua interface.
(At) 23:36 -0500 17/12/01, Emmanuel. M. Decarie ?crivait (wrote) :
*** 2. Can I put a Perl script or any other text file containing shell commands in the project that I could call from Application.applescript?
Suppose I want to build an AS Studio app that will open a window to choose a file, and then pass the path to the file to a Perl script that will sort every words in the file alphabetically with the number of occurrences for each word, and then return back the stats to the user in a new window.
- Could I embed the Perl script file in the project? - If so, how do I get the path to this file to be able to run it from Application.applescript (i.e do shell script "path in to my Perl script")
Tim Bumgarner wrote:
I don't have any experience with perl, but you should be able to do the following:
1. Create a perl script, say 'stats.perl'.
2. Add it to your project. This will typically end up in the 'Bundle Resources' build phase which usually put's it's products into 'Contents/Resources' inside of your built application.
3. Do the following somewhere in your script: 'tell main bundle to set thePath to path for resource "stats" extension "perl"'. This will return the full POSIX path to your 'stats.perl' script that is in your built application.
4. Pass that path to an execution of 'do shell script'. I'm not sure how to invoke a perl script, but I think you get the idea.
You can check out the 'path for' command for more variants. It listed in the Application Suite.
Emmanuel. M. Decarie wrote:
Yes! This is working. I just changed the Hello World example with this script:
on clicked theObject
tell main bundle to set thePath to path for resource "stats" extension "perl"
try
set thePath to "\"" & thePath & "\""
set r to do shell script thePath display dialog r
on error msgError
display dialog msgError
display dialog thePath
end try
end clicked
And put a stats.perl file in the Resources folder with this snippet:
#!/usr/bin/perl
use strict;
my $r = scalar (localtime);
print $r;
And then build the Hello World app and its working. The only problem that I had was that I forgot to set executable bit on the stats.perl file.
Wow, this is very very cool!!!!
macosx@perl.org archive
Back
|
|