Welcome to MacForumz.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

applescript remove duplicate list items

 
   Macintosh computer (Home) -> Apple Scripts RSS
Next:  How to hit the 'Step Frame' button in "DVD P..  
Author Message
Phantom

External


Since: Apr 12, 2007
Posts: 18



(Msg. 1) Posted: Mon Apr 28, 2008 10:59 pm
Post subject: applescript remove duplicate list items
Archived from groups: alt>comp>lang>applescript (more info?)

I'm wondering if anyone here knows of an elegant way to eliminate
duplicate values from an applescript list.

e.g. taking this list:
{"apple", "orange", "apple", "watermelon", "orange"}

and returning
{"apple", "orange", "watermelon"}


not a big priority, but it would help with one of my scripts. could't
find a answer with google, unfortunately, sorry to bother if this comes
up a lot.

thanks guys.

 >> Stay informed about: applescript remove duplicate list items 
Back to top
Login to vote
Dave Balderstone

External


Since: Mar 21, 2006
Posts: 2704



(Msg. 2) Posted: Mon Apr 28, 2008 10:59 pm
Post subject: Re: applescript remove duplicate list items [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <2008042815593316807-phantom@examplecom>, Phantom
<phantom DeleteThis @example.com> wrote:

> I'm wondering if anyone here knows of an elegant way to eliminate
> duplicate values from an applescript list.
>
> e.g. taking this list:
> {"apple", "orange", "apple", "watermelon", "orange"}
>
> and returning
> {"apple", "orange", "watermelon"}
>
>
> not a big priority, but it would help with one of my scripts. could't
> find a answer with google, unfortunately, sorry to bother if this comes
> up a lot.
>
> thanks guys.

Try this:

set list1 to {"apple", "orange", "apple", "watermelon", "orange"}
set list2 to {"apple", "orange", "watermelon"}
set list3 to {}

repeat with x from 1 to count of items of list1
set n to item x of list1
if n is in list2 and n is not in list3 then set end of list3 to n
end repeat

return list3

--
Help improve usenet. Kill-file Google Groups.
http://improve-usenet.org/

 >> Stay informed about: applescript remove duplicate list items 
Back to top
Login to vote
Simon Wolf3

External


Since: Sep 30, 2004
Posts: 11



(Msg. 3) Posted: Tue Apr 29, 2008 12:56 am
Post subject: Re: applescript remove duplicate list items [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Dave Balderstone <dave.RemoveThis@N_O_T_T_H_I_Sbalderstone.ca> wrote:

> In article <2008042815593316807-phantom@examplecom>, Phantom
> <phantom.RemoveThis@example.com> wrote:
>
> > I'm wondering if anyone here knows of an elegant way to eliminate
> > duplicate values from an applescript list.
> >
> > e.g. taking this list:
> > {"apple", "orange", "apple", "watermelon", "orange"}
> >
> > and returning
> > {"apple", "orange", "watermelon"}
> >
> >
> > not a big priority, but it would help with one of my scripts. could't
> > find a answer with google, unfortunately, sorry to bother if this comes
> > up a lot.
> >
> > thanks guys.
>
> Try this:
>
> set list1 to {"apple", "orange", "apple", "watermelon", "orange"}
> set list2 to {"apple", "orange", "watermelon"}
> set list3 to {}
>
> repeat with x from 1 to count of items of list1
> set n to item x of list1
> if n is in list2 and n is not in list3 then set end of list3 to n
> end repeat
>
> return list3

Sorry Dave but I've modified your code because I think that the original
post relates to a situation where there is only one list. If this is the
case then you need:

on run
set list1 to {"apple", "orange", "apple", "watermelon", "orange"}
set list2 to {}

repeat with x from 1 to count of items of list1
set n to item x of list1
if n is not in list2 then set end of list2 to n
end repeat

return list2
end run
 >> Stay informed about: applescript remove duplicate list items 
Back to top
Login to vote
Dave Balderstone

External


Since: Mar 21, 2006
Posts: 2704



(Msg. 4) Posted: Tue Apr 29, 2008 12:56 am
Post subject: Re: applescript remove duplicate list items [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <1ig4vvh.mpbdjr1o7dyniN%simon@ottersoftwaredotcom.invalid>,
Simon Wolf <simon.RemoveThis@ottersoftwaredotcom.invalid> wrote:

> Sorry Dave but I've modified your code because I think that the original
> post relates to a situation where there is only one list. If this is the
> case then you need:

Don't be sorry! I think you're right... I misread the original post.

Now, what if the OP needs to compare THREE lists?

<grin>

--
Help improve usenet. Kill-file Google Groups.
http://improve-usenet.org/
 >> Stay informed about: applescript remove duplicate list items 
Back to top
Login to vote
Phantom

External


Since: Apr 12, 2007
Posts: 18



(Msg. 5) Posted: Thu May 01, 2008 3:43 am
Post subject: Re: applescript remove duplicate list items [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 2008-04-28 16:56:07 -0700, simon DeleteThis @ottersoftwaredotcom.invalid (Simon
Wolf) said:

> Dave Balderstone <dave DeleteThis @N_O_T_T_H_I_Sbalderstone.ca> wrote:
>
>> In article <2008042815593316807-phantom@examplecom>, Phantom
>> <phantom DeleteThis @example.com> wrote:
>>
>>> I'm wondering if anyone here knows of an elegant way to eliminate
>>> duplicate values from an applescript list.
>>>
>>> e.g. taking this list:
>>> {"apple", "orange", "apple", "watermelon", "orange"}
>>>
>>> and returning
>>> {"apple", "orange", "watermelon"}
>>>
>>>
>>> not a big priority, but it would help with one of my scripts. could't
>>> find a answer with google, unfortunately, sorry to bother if this comes
>>> up a lot.
>>>
>>> thanks guys.
>>
>> Try this:
>>
>> set list1 to {"apple", "orange", "apple", "watermelon", "orange"}
>> set list2 to {"apple", "orange", "watermelon"}
>> set list3 to {}
>>
>> repeat with x from 1 to count of items of list1
>> set n to item x of list1
>> if n is in list2 and n is not in list3 then set end of list3 to n
>> end repeat
>>
>> return list3
>
> Sorry Dave but I've modified your code because I think that the original
> post relates to a situation where there is only one list. If this is the
> case then you need:
>
> on run
> set list1 to {"apple", "orange", "apple", "watermelon", "orange"}
> set list2 to {}
>
> repeat with x from 1 to count of items of list1
> set n to item x of list1
> if n is not in list2 then set end of list2 to n
> end repeat
>
> return list2
> end run

you're right on the mark... just one list. I figured there might have
been some list math possible, but this works great, too. thanks!
P.
 >> Stay informed about: applescript remove duplicate list items 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Script to remove duplicate events in iCal? - As an AppleScript newbie I'm trying to remove duplicates from an iCal calendar. Does anybody know of such a thing? My efforts are disappointing... I can not even access the properties of an event. The algorithm should be easy, I could ask iCal for..

sum if items in list - I want to get the sum of all items in a list quickly. What is the fastest way to do this given all items in the list are integers? set myList to {1, 2, 3} -- Can I quickly get 6 without using a repeat loop? -- Koncept << "Contrary to popul...

recent items list in OS X - Can anyone describe the relationship between the "recent items" Apple Menu item and the com.apple.recentitems.plist? I figure there's one copy in RAM and another on disk. By opening apps or documents, or by selecting the "Clear menu...

New to Applescript - Hello, I'm brand new to Applescript - I've done a lot with VBS but never touched Applescript. Are there some good script repositories online? AppleScript Editors? Manuals? Any help will be greatly appreciated!!! TIA, Bill bill@2burkes.com

Applescript RSS - Is there any way to acquire an RSS feed using Applescript? I'd like to be able to specify the RSS URL, then have Applescript consume the most recent 5 entries. Thanks, A
   Macintosh computer (Home) -> Apple Scripts All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]