I'm trying to get the number of tracks where both a composer as well as a a work has been set (to something other than the empty string). The second line in my posted script actually achieves this, correctly returning 2182, the third, one on the other hand, does not, even though I've simply switched the operands in the boolean conjunction around. The output for each of the two statements is given in parentheses.
The "use" statement was added in OS X 10.9, the 'it' identifier you can safely ignore, as it was simply added by Script Debugger where I copied it from the 'source' view. The script that I posted produces the exact same Apple event as this one:
tell application "iTunes"
count (every track whose composer ≠ "" and work ≠ "")
count (every track whose work ≠ "" and composer ≠ "")
where the two statements do in fact return different values for me (2182 vs. 13793), yet should not.
Or look at this single line instead:
tell application "iTunes" to (the work of (every track whose work ≠ "" and composer ≠ "")) contains ""
This should not return true, yet for me it does, as iTunes ignores the requirement that the work tag not be empty. Try it out for yourself, it will probably return 'true' for you as well, even though you don't have the work tag set anywhere. On the other hand the following, where the order of the operands is simply switched around, correctly returns 'false'.
tell application "iTunes" to (the work of (every track whose composer ≠ "" and work ≠ "")) contains ""
The question is whether this is a general issue, or whether it is idiosyncratic behavior of iTunes specifically. At this point everything's pointing towards a bug in iTunes' implementation of Apple event handling from my perspective.
tell application "iTunes" to get (count of (every track whose work = "No such work exists" and name ≠ ""))
Again, the first operand is completely ignored here. The returned count is simply of every track whose name is not empty. You should be able to reproduce this, regardless of whether you use the work tag for any tracks, or not.