Re: File best practice questions
Re: File best practice questions
- Subject: Re: File best practice questions
- From: "Gary (Lists)" <email@hidden>
- Date: Fri, 14 Mar 2008 18:31:49 -0400
- Thread-topic: File best practice questions
"Thomas Summerall" wrote:
> Ordering Finder around with applescript further confuses the mix.
The Finder's pretty dang scriptable. <shrug>
> My installer's pretty simple.
So is copying a folder from a package. See below.
> So my question is this: given that I have to allow the user to pick the
> destination folder and that I need to construct the path to my source folder
> in my installer package what is the best way to minimize or, dare I say,
> eliminate problematic paths and path conversions?
If you let the user choose the location for the incoming folder, the Finder
will have that choice. There can't be any "bad" paths, because the user
just chose a folder, which is therefore valid.
choose folder "Pick you folder location..."
That'll be a valid path. Who cares how the Finder stores it?
> Right now I keep pretty much everything in old style paths and tell the finder
> to duplicate the source folder to the target folder as paths. I build my
> source path like this (path to me as string) & ":Contents:My Install folder
> Name"
There is a built-in command for this:
path to resources "MyInstalledFolder" in directory "MyStuff"
That would find the folder 'MyInstalledFolder' inside a directory 'MyStuff'
inside the bundle/package's 'Resources' folder.
Not in 'Contents', as you're using. I think you're supposed to put your
stuff in 'Resources'. That's easiest, anyway, because you can use 'path to
resources'.
The "... in directory" parameter to the "path to resources" command is
optional, if your folder is not inside a sub-folder of 'Resources'.
> People have suggested using aliases instead of paths, but since I am
> constructing the paths anyway will that really help since they'll have to be a
> path string before they are an alias?
? A path is a string, an alias is an alias. You can turn a *valid* string
into an alias if: a) the string is a valid path that b) specifies an object
that really exists.
If you create some path string from other strings, then try to turn that
into an alias, it may not be a valid reference when you go to use it; and it
could easily fail (for the reasons you said...you put some invalid
characters in there, whatever.)
There is no "path v. alias" argument in AppleScript. They're different.
Path is not an AppleScript class (though it may very well be a property of
some object of some class. And some commands which use the term 'path'
return an alias. That's like "path to desktop" --> res. alias)
Here's what AppleScript provides, class-wise, related to "path-like" things:
alias
file
POSIX file
(reference)*
(string)*
* related, but indirectly...you get my meaning, I think.
The Finder uses files, aliases, posix files.
An alias is a real, existing, live thing...if the alias compiles, the file
thingy to which it points **already** exists.
Paths are strings, not some especially endowed top-level class. That's what
'alias' and 'file' are. ('file' is your FSSpec, right? I don't know that
stuff, or care, but I think that's what it is.)
> Does the Finder always want colon paths?
Yes, the Finder's separator is ":".
Unice's is "/".
Use posix file if you already have a posix-style path string that you want
to turn into something the Finder can use.
path to desktop
-- alias "Sunnydale:Users:Buffy:Desktop:"
POSIX path of (the result)
-- "/Users/Buffy/Desktop/"
POSIX file (the result)
-- file " Sunnydale:Users:Buffy:Desktop:"
> Should I not use the finder and instead use a shell command instead?
The Finder is the Mac file system interface, so, yeah, use it.
> Is there a class that encapsulates all this into something nicely abstract
> that Does The Right Thing (c) ?
What is this, Capitalism?
I don't understand that usage these days, where people put (tm) or (c) after
something that they capitalize. It's a curious thing, but makes sense in a
'productized culture' kind of way.
> Any tips or links to thorough documentation about the most foolproof way to
> avoid the common path and file errors would be appreciated. (I've read the
> basic file handling docs that define what a POSIX file is and so forth.)
Here's the AppleScript Language Guide (new and revised for 2.0):
<http://tinyurl.com/2wfrw3>
[Everyone can use that tiny url, so feel free to copy it for further
reference.]
HTH
--
Gary
_______________________________________________
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