Re: slash path to alias
Re: slash path to alias
- Subject: Re: slash path to alias
- From: Axel Luttgens <email@hidden>
- Date: Tue, 29 Jul 2008 18:03:45 +0200
Le 29 juil. 08 à 15:19, Luther Fuller a écrit :
Luther Fuller schrieb:
So ...
POSIX path of acntDir
if (last character of acntDir) = ":" then
set acntDir to (POSIX file the result) as text
else
set acntDir to ((POSIX file the result) as text) & ":"
end if
And now it works in both Tiger and Leopard.
My subject was a bit misleading. What I am really doing is getting a
path (text), which is independent of the OS, then extending the path
before converting to an alias. In the final script, I did not use
the code above, but used ...
if (offset of "/" in acntDir) > 0 then set acntDir to (POSIX file
acntDir) as text
if (last character of acntDir) ≠ ":" then set acntDir to (acntDir
& ":")
... which works.
Well, kind of... ;-)
I guess acntDir has been set with something like this:
tell application "Mail" to set acntDir to account directory of first
account
(if this is not the case, then you didn't tell us everything!)
That is, on Leopard, acntDir thus contains a file reference (see my
previous post).
Let's then suppose the HFS path of the account directory contains a
slash, as viewed in the Finder on an HFS volume; even if very
unlikely, it is possible to face such a case.
So, during the evaluation of
(offset of "/" in acntDir)
the file reference will be coerced into a string containing a slash;
the test will thus succeed and
(POSIX file acntDir)
will then yield a funny result, on which
(last character of acntDir)
will choke.
I was testing code with an iBook G3 10.4.11: very slow; in the next
room; no mouse; very tedious; I quit. And I'm not sure that the
second line is necessary, but it's safe.
As shown with the above boundary case, no, it's not. ;-)
To be really safe, the underlying problems must be identified:
- Mail returns a posix path under Tiger, a file reference under Leopard
- coercing a file reference to a string does not behave the same
under Tiger and Leopard
and the code must be written accordingly.
For example, if you really want an HFS path ending with a colon:
tell application "Mail" to set acntDir to account directory of first
account
if class of acntDir is Unicode text then set acntDir to POSIX file
acntDir
set acntDir to acntDir as text
if last character of acntDir is not ":" then set acntDir to acntDir &
":"
Of course, this could be optimized, but the logics should remain the
same.
I wonder if getting Leopard code to work in Tiger is worth the
effort. 99.9% of Leopard code does work in Tiger. Fixing the other .
1% is easy, but finding it can be time consuming and frustrating.
Agreed. :-)
Consider this little snippet which works in Leopard ...
set destFolder to choose folder with prompt the result default
location defLoc
tell application "Finder"
--
else if destFolder = (path to desktop) then
--
end tell
It fails in Tiger, leaving 'choose folder' stuck in an endless loop,
which made locating the problem easy, but what could possibly be
wrong with the code?
I don't fully grasp the above...
Under Tiger, "path to desktop" raises an error when appearing in a
tell "Finder" block, very likely because of a terminology clash.
Did you have that code enclosed in an "try" block?
Finally fixed it with ...
set destFolder to choose folder with prompt the result default
location defLoc
set deskAlias to (path to desktop)
tell application "Finder"
--
else if destFolder = deskAlias then
--
end tell
In the first snippet, one of the aliases is created outside the tell
Finder block, the other inside. They can never be equal in Tiger.
Hmmm.
Knowing that "choose folder" returns an alias, and that "desktop" is a
Finder item, this seems to be OK in both Tiger and Leopard, while
possibly being more readable:
set destFolder to choose folder with prompt the result default
location defLoc
tell application "Finder"
--
else if destFolder = (desktop as alias) then
--
end tell
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