• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: This worked yesterday: File path question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


References: 
 >Re: This worked yesterday: File path question (From: cris <email@hidden>)
 >Re: This worked yesterday: File path question (From: "Serge Belleudy-d'Espinose" <email@hidden>)

  • Prev by Date: Re: This worked yesterday: File path question
  • Next by Date: Re: library of subroutines - help needed
  • Previous by thread: Re: This worked yesterday: File path question
  • Next by thread: Re: This worked yesterday: File path question
  • Index(es):
    • Date
    • Thread