Re: What type is the finder selection?
Re: What type is the finder selection?
- Subject: Re: What type is the finder selection?
- From: Christopher Nebel <email@hidden>
- Date: Mon, 12 Aug 2002 14:01:58 -0700
On Monday, August 12, 2002, at 01:21 PM, Doug McNutt wrote:
"selection" returns a list of the items currently selected in the
finder. How can I tell if they are disks, folders, or files?
** This is where I am:
tell application "Finder"
set theSelection to selection
end tell
repeat with theThing in theSelection
set theType to word 1 of theThing
end repeat
** This is what comes out:
tell application "Finder"
get selection
--> {disk "Hubble", file "Air Traffic.pdf", trash}
get word 1 of disk "Hubble"
--> Finder got an error: Can't get word 1 of disk "Hubble".
Why is finder trying to get word 1? I'm outside of the tell block. I
expect theThing to be the text 'disk "Hubble"' but it seems to be just
"Hubble".
To answer the second question, theThing (technically, the contents of
theThing, because theThing is a reference to an item of theSelection)
is a Finder object specifier. When you ask for elements of an object
specifier, AppleScript is smart enough to send the request to the
application that owns the specifier, even without a tell block.
To answer the third question, theThing is an object specifier, *not*
text. It happens to display in the result window as 'disk "Hubble"',
but that's not the same thing as the string "disk \"Hubble\"". Read
chapters 3 and 5 of the AppleScript Language Guide if you're unclear on
the difference.
To answer the first question, change "word 1" to "class". You'll get a
class as defined in the Finder's dictionary -- disk, folder, or one of
(I think) five file classes. (Again, these are not strings.) You
discovered the "kind" property (which really is a string), but as you
also discovered, it's not very reliable, because its value for files
depends on the owning application, and even for disks and folders it
can change depending on the user's primary language.
(If you're using Mac OS X, you might discover at some point that you
can't get elements or properties of the selection in a single
statement, e.g. "get the class of every item of the selection". You
have to get the selection and then loop over it, as you're currently
doing. It's a known bug.)
--Chris Nebel
AppleScript Engineering
_______________________________________________
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.