Re: Madness & frustration... What is a file? What is a Path?
Re: Madness & frustration... What is a file? What is a Path?
- Subject: Re: Madness & frustration... What is a file? What is a Path?
- From: Nigel Smith <email@hidden>
- Date: Thu, 13 May 2004 12:39:11 +0100
On 12/5/04 15:14, "Cliff Pruitt" <email@hidden> wrote:
>
Tell Application "Whatever"
>
set homePath to path to home folder
>
set theFile to homePath & ":Documents:Folder 1:Folder 2:file.txt"
>
open theFile
>
End Tell
Another couple of ways. Just these one-liners, nothing else needed:
open file ((path to "cusr" as text) & "Documents: Folder 1:Folder
2:file.txt")
And:
open file ("" & (path to documents folder) & "Folder 1:Folder
2:file.txt")
These both Walter's explanations -- you can see that, in the first, we get
the path to the current user folder, then explicitly make that into text so
we add a string to it, add the string to get our full file-path, then open
the file with that file-path.
In the second we use what Walter explained about how AS will concatenate two
items if the second is the same class, or can be coerced into the same
class, as the the first. Because we start with text, the empty string, "path
to documents folder" is coerced from an alias to text and concatenated, then
our string added to the end of that. Again, we open the file with that
file-path.
Two different ways of doing the same thing -- you'll see both on the list.
Note also that there is a "path to documents folder", rather than you having
to find the current user than add "Documents:" on the end. More "path to"s
are listed in the Standard Additions dictionary.
One other thing about alias "blah" against file "blah". If you write a
script with
open alias "MacHD:Users:Shared:test.txt"
...it will only compile if that file exists. BUT, if you save and close the
script then move the file, the script will track it and change automatically
to reflect the file's new position. If I moved the file to my desktop and
opened the script that line would read
open alias "MacHD:Users:nigel:Desktop:test.txt"
If you use
open file "MacHD:Users:Shared:test.txt"
...the file need not exist for the script to compile. If it is there, fine.
If you then move it to somewhere else, the script will *not* track it as did
the alias.
HTH,
Nigel
_______________________________________________
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.