Re: alias is folder?
Re: alias is folder?
- Subject: Re: alias is folder?
- From: Christopher Nebel <email@hidden>
- Date: Mon, 28 Apr 2003 18:01:26 -0400
On Monday, April 28, 2003, at 05:31 AM, John Delacour wrote:
It occurs to me that Matt may not have asked the question he intended
to ask
At 5:14 pm -0700 26/4/03, matt neuburg wrote:
Given an alias, what's the best way to ask the Mac OS X Finder whether
it's a folder? Thx - m.
If by that he means Given an alias file, how do I discover whether it
points to a folder; then this method will not work -- it will return
'alias file'. And nor will Paul's methods.
True enough; I hadn't considered that. Of course, the solution just
boils down to saying "get the original item of myAlias" first, and then
using the result as the thing you look at.
Here is an example of what I mean and a solution to the question he
may have meant to ask:
tell application "Finder"
set _sele to item 1 of (get selection)
--> alias file "0_scripts_eudora" of folder "jd"...
set _path to "" & _sele
--> "dx:Users:jd:0_scripts_eudora"
set _item to "" & original item of file _path
--> folder "Scripts" of folder "Eudora Folder...
--> "dx:Users:jd:Documents:Eudora Folder...
set isFolder to _item ends with ":" and item does not end with ":app:"
{isFolder, class of _sele is folder}
--> {true, false}
end tell
Two objections to this script:
First, there's no reason to convert the selection to a path and then
back into a file reference to get its original item -- it's a perfectly
usable file reference as it is.
set _sele to item 1 of (get selection)
--> alias file "0_scripts_eudora" of folder "jd"...
set _item to "" & original item of _sele
--> folder "Scripts" of folder "Eudora Folder...
--> "dx:Users:jd:Documents:Eudora Folder...
Second, your attempt to screen out packages (presumably you meant
".app:", not ":app:") only works for applications, and won't do
anything for other packaged items -- .rtfd files, .osax bundles, nibs,
etc. The only way to determine package-ness reliably is to use the
"package folder" attribute of "info for" (or to ask the Finder for the
class of the item.)
I dislike the ends-with-a-colon trick, mostly for philosophical reasons
-- it's insufficiently object-y for my tastes, and relies on a
convention that is in no way enforced by the operating system (and
doesn't apply to other path styles.) Admittedly, it does work
perfectly well for what it does, but I'd rather there were a better
way. System Event's disk-folder-file suite is a step in this direction.
--Chris Nebel
Apple Development Tools
_______________________________________________
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.