• 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: Checking for duplicates in lists
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Checking for duplicates in lists


  • Subject: Re: Checking for duplicates in lists
  • From: Emmanuel <email@hidden>
  • Date: Fri, 2 Jan 2004 17:04:30 +0100

At 10:15 PM +0100 29/12/03, Richard Rvnnbdck wrote:
>I need some scripts for dealing with possible duplicates in iTunes.
>Performance is critical for the user experience so I thought that the best
>way would be to see if there are multiple occurrences in a list.

-----------
set myTracks to (name of file tracks) of myPlayList
-----------

What I [would] do:
1. Make myTracks into lines separated with LF (ascii 10):

----------- tested
set text item delimiters to {ascii character of 10}
set myTracks to myTracks as text
-----------

2. Sort the list: use the shell's "sort" command:

----------- tested
set x to quoted form of myTracks
set x to do shell script "echo " & x & " | sort"
-----------

3. Use the regular expressions to suppress duplicates. I use the Satimage osax [1]:

----------- tested
set x to change "^(.+)(\\r\\1)+" into "\\1" in x with regexp
-----------

but you should be able to program the same thing with the shell's "grep" command.

4. Finally get it as a list (if that's what you really want! Text lines are finally a cool way of handling a list when you have "sort" and the regular expressions).

----------- tested
set text item delimiters to {return} -- by default "sort" inputs LF's and outputs CR's
set myTracks to text items of x -- use "count paragraphs of x" and be more careful if you expect > 4000 items
-----------

Emmanuel
Satimage-software
<http://www.satimage-software.com>

[1] A free and cool scripting addition available at <http://www.satimage-software.com>.
Dictionary viewable at <http://www.satimage-software.com/en/dictosaxx.html>.
Documentation about the Regular expressions in the Satimage osax available as a pdf at:
<http://www.satimage-software.com/en/downloads_documentation.html>.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Checking for duplicates in lists
      • From: Christopher Nebel <email@hidden>
  • Prev by Date: Re: AB: launch app in background?
  • Next by Date: Handling Unicode Text
  • Previous by thread: Re: AB: launch app in background?
  • Next by thread: Re: Checking for duplicates in lists
  • Index(es):
    • Date
    • Thread