Re: This worked yesterday: File path question
Re: This worked yesterday: File path question
- Subject: Re: This worked yesterday: File path question
- From: Ted Wood <email@hidden>
- Date: Sun, 17 Dec 2000 00:31:38 -0800
At 20:49 +0100 16/12/00, cris wrote:
> > Changing to "open file alias..." got it to start working again.
>Funny, i just had the same trouble (randomly) and i changed from "alias" to
>"file". :) But i think that was not the important change. My previous
>statement was inside a finder tell, now it's alone and works since a week
>without any trouble.
Well, since it took me awhile to figure it out...
Just a reminder to everyone, and especially myself :)
set xAlias to alias "myDisk:myFile"
and
tell application "Finder" to set xAlias to alias "myDisk:myFile"
both are equivalent and return an alias. But
set xFile to file "myDisk:myFile"
and
tell application "Finder" to set xFile to file "myDisk:myFile"
return respectively:
- file "myDisk:myFile", a file specification;
- file "myFile" of disk "myDisk" of application "Finder", a document file.
There are not equivalent at all.
My workaround for comparing them is to constrain everything to strings.
End of my sunday morning practice.
Serge
Hi Serge,
Definitely, using strings is one way to keep everything working, but
remember aliases are understood regardless of the application in
context, so long as the targeted object (file, folder, etc.) exists.
One workaround for this I use is a combination of strings and
aliases, as in the following example:
-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=
EXAMPE: (when a folder is known to exist, but the file may or may not exist)
set myFile to ((alias "disk:existing_folder:" & "file_name_here") as
string) as alias
As you can see in this example, the known folder is specified as an
alias, so if it changes in any way, the alias will still resolve. A
similar format can be used for any number of nested folders. If you
didn't first coerce to a string, you'd get a list {alias
"disk:existing_folder:", "file"}, so we coerce to a string, but then
to an alias for more flexibility throughout the rest of the script.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
The bottom line of my point is "try to use aliases whenever
possible". Coerce to strings and then back to aliases when storing
file paths in variables to be used throughout the script. It won't
affect the compilation of your script, but will ensure smoother
running as folders and files change and move around in the Finder.
Cheers,
Ted.