Re: perl from applescript
Re: perl from applescript
- Subject: Re: perl from applescript
- From: "Mark J. Reed" <email@hidden>
- Date: Sun, 28 Aug 2005 12:52:28 -0400
More generally, if you have your Perl script (or any other command)
output a value using AppleScript's literal syntax, you can "run
script" that output to get the value interpreted just as AppleScript
would if you typed it inside a script. This is, of course, a
dangerous technique for general use, and should only be used when you
have complete control over the program being run. It's also somewhat
inefficient in that it has to instantiate an entire new copy of the
AppleScript interpreter to do the evaluation. But it is completely
general in that the program can output a list, a record, a plain
number, a string, whatever.
For instance, this perl script will output a file's inode as an
AppleScript record:
#!/usr/bin/perl -w
my @fields = qw(dev ino mode nlink uid gid rdev size atime mtime ctime
blksize blocks);
my @stat = stat($ARGV[0]) or die "$0: could not stat $ARGV[0]: $!\n";
print "{", join(", ", map { qq|$fields[$_]: ${\($stat[$_])}| }
0..$#fields), "}\n";
I saved it as /usr/local/bin/astat. If I run it from AppleScript this way:
set myFile to (choose file)
set stat to (run script (do shell script "/usr/local/bin/astat " &
POSIX path of myFile))
Then I have a record in "stat" with values from the inode of the selected file.
Of course, the time values are raw UNIX time_t values: integer number
of seconds since Jan 1, 1970 00:00:00 UTC. That's not easy to work
with from AppleScript as they are, but the Perl could be modified to
make them more AS-friendly.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden