Re: Unixy question
Re: Unixy question
- Subject: Re: Unixy question
- From: John W Baxter <email@hidden>
- Date: Sun, 19 May 2002 11:44:43 -0700
At 5:33 -0500 5/18/2002, garrett wrote:
>
Sometime 'round 05/09/2002 12:08 AM, Paul Skinner at email@hidden
>
described:
>
>
> Can someone translate this into the actual string I need to give to a
>
> 'do shell script' command to get the time with microseconds ?
>
> I still feel like I'm reading a french textbook. I know all of these
>
> words, but I can't seem to arrange them into meaningful sentences.
>
>
I think what u want more is like this:
>
>
set theMonth to do shell script "date +%m" as string
>
set theDate to do shell script "date +%d" as string
>
set theYear to "20" & (do shell script "date +%y" as string)
>
set theHour_24 to do shell script "date +%H" as string
>
set theMinute to do shell script "date +%M" as string
>
set theTime_long to do shell script "date +%r" as string
>
Once you call date a second time to get one instant's values, you open the
script to perverse effects such as
We start very late on October 31:
theMonth becomes 10
Oops...now it's early on November 1:
theDate becomes 1
theHour_24 becomes 00
and so on (had I selected late December 31 the "problem" extends itself to
the year).
This sort of thing would be better done with ONE call to date, with a
format which produces a string which can then be parsed using the
AppleScript TIDs to extract the parts. For example (adjusted slightly):
set x to do shell script "date '+%m|%d|%y|%H|%M|%S'"
set {oldTID, AppleScript's text item delimiters} to {AppleScript's text
item delimiters, {"|"}}
set {theMonth, theDate, theYear, theHour, theMinute, theSecond} to text
items of x
set AppleScript's text item delimiters to oldTID
{theMonth, theDate, theYear, theHour, theMinute, theSecond}
-->{"05", "19", "02", "11", "32", "10"}
But none of that has anything to do with getting the time "with
microseconds" since date doesn't go below the second.
apropos time
leads us to the tantalizing Perl module Time::HiRes, which we don't have.
That module does provide a way to get the time including microseconds (in a
Perl script):
($seconds, $microseconds) = gettimeofday;
So, *PERHAPS* going to CPAN (the Perl module collection) and getting the
Time stuff would do the trick. Or perhaps not...copying over the Time
directory from the MacPerl library (some version of which I happen to have)
into a suitable place with suitable permissions still led to an error in a
test Perl script. I haven't looked into why.
AppleScript Studio and a call into the libraries from there would be
another potential approach (if microseconds are available in the available
frameworks).
--John the Unhelpful
--
John Baxter email@hidden Port Ludlow, WA, USA
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.