• 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
Accessing item elements in Applescript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Accessing item elements in Applescript


  • Subject: Accessing item elements in Applescript
  • From: Brian Webster <email@hidden>
  • Date: Thu, 5 Dec 2002 17:33:09 -0600

There was a recent discussion regarding using the term "item" for accessing elements of an object in Applescript without regard to their class, and I've run up against what appears to be a bug in the Cocoa scripting system relating to that, and I was wondering if anyone knew of a workaround. I've CCed this to the applescript-implementors list, but replies should probably go to the cocoa-dev list.

I don't even have to describe my own program, because you can see exactly the same behavior if you script the System Events application that comes with 10.2. Among other things, System Events allows you to script the filesystem without having to rely on the Finder. There are classes for folders, files, disks, etc., all of which inherit from the "item" class.

It may appear at first that it works just fine, when you run a script such as:

tell application "System Events"
get every item of disk "Macintosh HD"
end tell

This returns you a list of items on the root level on your hard drive. Fine. However, if you try the following:

tell application "System Events"
get item 1 of disk "Macintosh HD"
end tell

What you get back is a reference to the disk itself, not the first item it contains. Also, "count items of disk "Macintosh HD"" will return 1 in all cases. The forms "some item", "middle item", and "item named "foo"" will work, but things like "last item" and "items 2 through 4" will not, returning the parent of the requested object instead.

So what I'm wondering is:

1. Has anyone run into this before and is it reproducible on other machines?
2. Any idea what on earth is happening to cause this behavior?
3. Any idea on how to get around it?

--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: runtime error using NSArray with NSButton
  • Next by Date: Re: Interface Builder 2.3 - Show Info doesn't work, can't open the info panel
  • Previous by thread: Re: -methodForSelector: doesn't fail when it should
  • Next by thread: Re: Accessing item elements in Applescript
  • Index(es):
    • Date
    • Thread