• 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
Re: List of length one
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: List of length one


  • Subject: Re: List of length one
  • From: Christopher Nebel <email@hidden>
  • Date: Sat, 26 May 2007 00:58:45 -0700

On May 25, 2007, at 2:55 PM, Gil Dawson wrote:

To operate on a folder with many files in it, I wrote, using MacOS 9.2.2 and Script Editor 1.8.3,...

tell application "Finder" to ¬
  set FilesList to name of every file in folder EVCNdbFolder ¬
                whose name begins with "evcn"

     --> {"evcnall070514.fp5", "EVCNfxd070514.fp5"}

...which produces what could be described as a list of length 2, containing two strings representing the two matching files. All good.

However, if I change the "whose" criterion, so that only one file matches...

tell application "Finder" to ¬
  set FilesList to name of every file in folder EVCNdbFolder ¬
                whose name begins with "evcnall"

     --> "evcnall070514.fp5"

...which is not a list but a string of length 17, containing 17 characters.

Is this a bug in 9.2.2 AppleScript? I notice it does not seem to happen with Tiger and Smile.

It's a bug in Finder 9.2.2. Smile has nothing to do with it.

How does one handle this situation?

if ((class of FilesList) as string = "string") then ¬
   set FilesList to {FilesList}

...seems to fix the problem. Is there a better way?

Well, you don't need to convert the class to a string, you can just compare them directly:


	if class of FilesList is string then ...

Except that it would be more reliable to test if the class is list instead, since the "string" result might actually be Unicode text. Alternatively, coerce the result to list ("blah as list"), or concatenate it with an empty list, which amounts to the same thing.


--Chris Nebel AppleScript Engineering

_______________________________________________
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
References: 
 >List of length one (From: Gil Dawson <email@hidden>)

  • Prev by Date: Re: List of length one
  • Next by Date: Re: List of length one
  • Previous by thread: Re: List of length one
  • Next by thread: Re: List of length one
  • Index(es):
    • Date
    • Thread