Re: Is this legit? [POSIX]
Re: Is this legit? [POSIX]
- Subject: Re: Is this legit? [POSIX]
- From: Axel Luttgens <email@hidden>
- Date: Wed, 23 Jul 2008 23:07:29 +0200
Le 23 juil. 08 à 17:14, Nigel Garvey a écrit :
I've been looking for a way to get the name of the time zone in
which a
machine's currently operating (eg. "Europe/London"). While following
clues in parts of the system where I don't normally venture, I've
noticed
that if I coerce "/etc/localtime" to POSIX file, the reference
changes to
the current time zone file:
file "PowerBook HD:usr:share:zoneinfo:Europe:London"
I can coerce this to Unicode text (to avoid some ambiguity with the
POSIX
file) and get the POSIX path of the result, which gives a text ending
with the very information I want:
set tzPath to POSIX path of ("/etc/localtime" as POSIX file as
Unicode text)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "zoneinfo/"
set tz to text item 2 of tzPath
set AppleScript's text item delimiters to astid
tz --> "Europe/London"
This works for other time zones too. But is the "/etc/localtime"
coercion
trick a legitimate usage, or is it just something that happens to
work in
Tiger and Jaguar?
Hello Nigel,
As Michelle already wrote, it works in Leopard too.
But I nevertheless feel somewhat disturbed with the above.
File /etc/localtime is a symbolic link.
Asking for:
"/etc/localtime" as POSIX file
looks like a string to file specification coercion, even if this has
never been explicitely defined in the language (but I may be wrong).
Anyway, that coercion seems to resolve the symbolic link, a bit à la
Finder, for which an alias file always targets the target and not the
alias file itself:
"/etc/localtime" as POSIX file
--> file "PowerBook HD:usr:share:zoneinfo:Europe:Brussels"
But then what should be thought about this one:
POSIX path of ("/etc/localtime" as POSIX file)
--> "/etc/localtime"
Looks like one has a half-baked link resolution...
But let's go further.
"/etc/localtime" as POSIX file as Unicode text
--> "PowerBook HD:usr:share:zoneinfo:Europe:Brussels"
(could simply have been "as string" or "as text" in Leopard, because
of its unicode awareness)
So, we now have the HFS path of the target file.
But then we ask for the POSIX path of a string:
POSIX path of ("/etc/localtime" as POSIX file as string)
--> "/usr/share/zoneinfo/Europe/Brussels"
Again, strictly speaking, "POSIX path" is a property of a file, not of
a string; I suspect such things to be possible because of earlier
implementation errors, just maintained for the sake of backwards
compatibility.
As a result, I would tend to avoid any ambiguity, even at the cost of
spawning a shell process:
do shell script "/usr/bin/readlink /etc/localtime"
--> "/usr/share/zoneinfo/Europe/Brussels"
This should work with any incarnation of AppleScript knowing about "do
shell script", without relying on some language's strangeness.
Splitting hairs,
Axel
_______________________________________________
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