• 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: Position of an element in a list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Position of an element in a list


  • Subject: Re: Position of an element in a list
  • From: Yvan KOENIG <email@hidden>
  • Date: Wed, 2 Aug 2017 14:16:59 +0200

> Le 2 août 2017 à 12:37, Shane Stanley <email@hidden> a écrit :
>
> On 2 Aug 2017, at 6:29 pm, Nigel Garvey <email@hidden> wrote:
>>
>>> Would fail under 10.10 and earlier.
>>
>> I wondered about that myself. But would it? AS dates wouldn't be bridged
>> to NSDates, 'tis true, but wouldn't they then be packaged as
>> NSAppleEventDescriptors? They only need to be compared here, not
>> understood. The handler works with AS values like 'Wednesday'.
>
> Running under 10.10 in Parallels here, it fails. But then so does
> 'Wednesday', so I suppose I could be seeing an artefact of emulation. Maybe
> someone running 10.10 for real can check.
>
> I have a vague memory of NSAppleEventDescriptor essentially treating isEqual:
> as little more than a pointer comparison, but I might be wrong on that. (Or
> that could have changed since 10.10, I suppose.)
>
> The other point worth mentioning is that the ASObjC method always considers
> case when strings are involved, unlike AppleScript.
>
> --
> Shane Stanley <email@hidden>
> <www.macosxautomation.com/applescript/apps/>, <latenightsw.com>


Here is what I got under two systems.

# comparing 10.10.5 & 10.12.6
use AppleScript version "2.4" # requires Yosemite or higher
use framework "Foundation"
use scripting additions

on indexOf:aValue inList:theList
        local |⌘|, theArray, theIndex # useful for Script Debugger

        set |⌘| to current application
        set theArray to |⌘|'s NSArray's arrayWithArray:theList
        set theIndex to theArray's indexOfObject:aValue
        if theIndex = |⌘|'s NSNotFound then
                return 0
        else
                return (theIndex + 1) # +1 because ASObjC counts starting from 0
        end if
end indexOf:inList:

set theList to {5, 2, 6, 9, 4, "TTT", 6, current date, 3, weekday of (current
date)}
--> under 10.10.5 --> {5, 2, 6, 9, 4, TTT, 6, date mercredi 2 août 2017
14:02:40, 3, Wednesday}
--> under 10.12.6 --> {5, 2, 6, 9, 4, TTT, 6, date mercredi 2 août 2017 à
14:09:51, 3, Wednesday*)


its indexOf:(current date) inList:theList
log "index of (current date) [" & (current date) & "] : " & result
--> under 10.10.5 --> (*index of (current date) [mercredi 2 août 2017 14:02:40]
: 0*)
--> under 10.12.6 --> (*index of (current date) [mercredi 2 août 2017 à
14:09:51] : 8*)

its indexOf:(weekday of (current date)) inList:theList
log "index of (weekday of (current date)) [" & weekday of (current date) & "] :
" & result
--> under 10.10.5 --> (*index of (weekday of (current date)) [Wednesday] : 0*)
--> under 10.12.6 --> (*index of (weekday of (current date)) [Wednesday] : 10*)


Yvan KOENIG running Sierra 10.12.6 in French (VALLAURIS, France) mercredi 2
août 2017 14:15:17








 _______________________________________________
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

  • Follow-Ups:
    • Re: Position of an element in a list
      • From: Shane Stanley <email@hidden>
References: 
 >Re: Position of an element in a list (From: "Nigel Garvey" <email@hidden>)
 >Re: Position of an element in a list (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Position of an element in a list
  • Next by Date: Re: Position of an element in a list
  • Previous by thread: Re: Position of an element in a list
  • Next by thread: Re: Position of an element in a list
  • Index(es):
    • Date
    • Thread