Need help with IF function script


I am wanting to help iTunes sort properly.

At the moment (default sorting) iTunes sorts like this:
If Artist name starts with either "A" or "The" (are there more? I only know of these two) iTunes ignores these.

  • "A Perfect Circle" doesn't get sorted to 'A' but instead to 'P'
  • "The Beatles" doesn't get sorted to 'T' but instead to 'B'

Now I like how iTunes sorts the artists that contain "The" but not "A".
I would like "A Perfect Circle" to be sorted to 'A', but "The Beatles" to be sorted to 'B'.

Now this involves using the tag field PERFORMERSORTORDER.
But I also need an IF function to help me out.
It would search the %artist% field for "The" (which will always be Mixed caps ie not: the, tHe, thE, THe, tHE, ThE, THE; and will always be the first three letters if the %artist% string was to contain one; but not neccessarily the only "The" within the string though).
If the function found a "The" then it would use the %artist% string value, minus the "The", as the value in the PERFORMERSORTORDER tag ("The Beatles" becomes "Beatles"). If it didn't find "The" than it would just use the %artist% string value as it is ("A Perfect Circle" stays as "A Perfect Circle").

Make any sence?

Any help would be much appreciated!


Just copy everything to performersortorder and then use this kind of action to the "The "


A lot simpler than I thought...

Thanks a lot for that!


Hi Dano,

I want to create an action group to format sorting tags after being filled from normal tag. Starting "The ", "A " etc should be moved to the end of the (sort) tag. E.g. The Beatles -> Beatles, The
There are several SORT tags that need this conversion (album, Artist, Title).

  1. Is it possible to add in the same regular expression several patterns?
$regexp(%artistsortorder%,^The (.+),$1',' The)

$regexp(%artistsortorder%,^A (.+),$1',' A)

Maybe using pipeline character could be feasible but I haven't realized yet.
  1. Since the same set of process should be used for several tags is there any way to make it dynamic?

Thank you,