class = folder: broken on yosemite?

does this fail for anyone else on yosemite:

property hfspath : "Pathto:Downloads:" -- folder path in hfs format
set this_folder to alias hfspath
tell application "Finder"
	set added_items to every item of this_folder whose class is not folder
end tell

result:

error “Finder got an error: Unknown object type.” number -1731

Hi. I’m not running Yosemite yet, but your script also fails in Mavericks due to the malformed path. Try:


set this_folder to (path to downloads folder)
tell application "Finder" to this_folder's items whose its class is not folder

This one, which uses a correct syntax, behave flawlessly with Yosemite.

Yvan KOENIG (VALLAURIS, France) dimanche 26 octobre 2014 19:43:28

What’s wrong with that syntax? Obviously “Pathto:Downloads:” is a dummy path, but if it is a valid HFS path, what’s the problem? My “path to downloads” folder (i.e. ~/Downloads/) is not the downloads folder I actually use; I use one on an external disk.

It seems that you didn’t really opened your eyes.
The error is not in the pathname ” assuming of course that you define an existing one.
It’s the word “its” which is missing in your script but is present in Marc’s one.

Your script must be edited this way :

property hfspath : "Pathto:Downloads:" -- folder path in hfs format
set this_folder to alias hfspath
tell application "Finder"
   set added_items to every item of this_folder whose its class is not folder # inserting its before class makes the difference
end tell

Yvan KOENIG (VALLAURIS, France) dimanche 26 octobre 2014 20:30:20

Well, I’ll be da**ed. I thought that was optional, and the syntax without “its” worked at least up through 10.7.5. Never would have guessed. Explanation of the necessity of “its” would be be enlightening. Thanks.

It’s interesting how AppleScript can distinguish between its and it’s. I’m amazed all the time!

Edited: in these cases, I usually use where instead of whose.

Looks like a bug to me.

Marc’s cure might be less linguistically painful with ‘where’ instead of ‘whose’ (as I see Kel has now suggested):

tell application "Finder" to set added_items to this_folder's items where its class is not folder

Or of course there’s:

tell application "Finder" to set added_items to this_folder's files

Actually, I don’t know if this is a bug, because the target can be each item. Think I’ve seen this when they changed the ‘selection’.

Edited: what I mean is that the target might be the list or the items of the list.

It actually isn’t obvious to me. People on this forum come in every variation of wisdom and experience. Unless your name is Nigel, Shane, or Stefan, I have to assume you are, um, knowledge challenged. No offense. :slight_smile:

Unlike Nigel, I have no linguistic qualms with using whose it vs. where it, and I don’t believe this to be a bug. It is self-referential to the object and prevents a reference form change. Consider the differences between these statements…


set this_folder to (path to downloads folder)

# a "solidified" reference:
tell application "Finder" to this_folder's items  
--> {document file "About Downloads.lpdf" of folder "Downloads" of folder "whosoever" of folder "Users" of startup disk of application "Finder", document file...}

# --> a "proto" reference:
tell application "Finder" to this_folder's items's it 
--> every item of alias "Macintosh HD:Users:whosoever:Downloads:"

English is not my main language but from my school years, I remember than :
its is a possessive adjective
while
it’s is a short form for it is

So I’m not surprised to see that Applescript is able to make the difference between the two completely different words.

I agree that in the given case, where is neater than whose but, most of the time, I don’t think to use it.

When I tested, I started from the original script with a valid pathname and got an error so, I looked at Marc’s code and saw that the only difference was the three letters word “its” so, I inserted it in the original code and bingo, it worked.
My understanding is that it helps AppleScript to point to the correct object which it doesn’t without it.
I already pointed here that when we are trying to grab or at least read properties whose name is displayed in blue italic in the Script Editor, its is quite always required.

tell application "Finder" to tell window 1
	name # name is in purple --> its is not required
	log result (*Tids in late Pages*)
	zoomed # zoomed is in purple --> its is not required
	log result (*false*)
	its class # class is in blue italic --> its is required
	log result (*Finder window*)
	its icon view options # icon view options is in blue italic --> its is required
	log result (*icon view options of Finder window id 1179*)
end tell

Yvan KOENIG (VALLAURIS, France) dimanche 26 octobre 2014 22:59:47

Hi Yvan,

Great job of deducing that! Who would have ever thought that Apple would have changed the syntax. I tried it the whose form and it doesn’t work in many situations.

About the ‘it’. The hard part about it in the English language you can see when you actually use the word ‘it’. Suppose I said to someone to not use so many its in their essay, but to be specific. The student then writes to their friend that I said not to use too many its or itses or was it its’?. Then, you have many forms of it that mean different things. The plural its, the contractions it’s and how do you write many itses. :smiley: I don’t know about you but in high school I often misspelled it. In college, my professor wrote me a note on my term paper! :confused: It’s not that simple to me.

I have it down now. :slight_smile: No, I’m starting to get mixed up now. :smiley:

Have a good day,
kel

I agree. If you run this:

set this_folder to (path to downloads folder)
tell application "Finder" to this_folder's items whose its class is not folder

You will see in the log:

tell application "Finder"
	get every item of alias "Macintosh HD:Users:shane:Downloads:" whose class ≠ folder

No its there.

Don’t be deceived. AppleScript will happily work with this too:

tell application "Finder" to this_folder's items whose it's class is not folder

Hi, Shane. If this is a bug, it’s very long-lived and widespread. I browsed through my script library”at least the part that’s still searchable text”and I can find instances of whose its from 6+ years ago; assumedly, I was using OS 10.4 back then. Multiple applications, including the Adobe suite, seem to require its to attain/retain a usable reference form.

Another example:

tell application "Adobe Illustrator"'s document 1 to set (path items whose its layer's name = "whatever")'s fill color to (get swatch 11's color)

Marc,

Your example is correct, but it’s a different case. You’re using its to make the filter apply to an element belonging the class preceding the whose; the case here is direct. It’s no different than:

set this_folder to (path to downloads folder)
tell application "Finder" to this_folder's items whose name is not "xyz"

Which still works fine.