Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Sorting by Date Added, but I how can I have songs sorted by track number?

Hopefully the subject says it all - I sort my iTunes library by Date Added (so my most recent purchases are on top). However, purchased albums then display the songs in whatever random order they were downloaded and not in ascending track order so I can just play the album properly. Is there a way to do this?

MacBook Pro (17"), Mac OS X (10.6.2), 3GB RAM

Posted on Feb 5, 2011 4:52 PM

Reply
34 replies

Feb 14, 2011 3:07 PM in response to turingtest2

Well, we definitely share the same opinion about how "natural" AppleScript is 😉. Anyway, I'm more than happy to stoke Doug's fire, but if you've already got a script (albeit in a different language) then would you be able to forward it to him and I could follow up with a request to implement the script. That way he gets it from two sides and maybe it'll inspire him more to tackle this - assuming he's not reading this thread and has figured out our strategy 😉.

Nov 15, 2011 1:27 AM in response to Mick_M

And I thought I was the only one that wondered about the same exact thing. I would also like to point out that if you buy multiple albums at a time, even if they're coming from the iTunes store, it throws off the download order and affects the "date purchased" by album solutions offered. What drives me nuts is that I'm nearly 100% certain that the SoundJam application (anyone here remember that?) kept albums organized by track number even when sorting by date added. SoundJam was essentially the application apple bought to develop iTunes and I remember that's one of the first things I notices was how sorting had changed, even though this was over 10 years ago now...

Jan 23, 2012 6:08 AM in response to turingtest2

Turingtest2,


Great script!


I'm having a problem though. With about 80% of the tracks I've tested, I kept getting the following message: "Script: SortDateAdded.vbs ; Line: 382; Char: 9; Error: The track is not modifiable. Code: A0040203; Source: Null." Now, if I delete the "Restore extra data for media" lines 381-39x, everything works, but no playedcount, skiptedcount, etc, is restored. This happens both with recently encoded tracks, with no counts whatsoever, and with old CDs with many playedcounts. Most my tracks were ripped and encoded outside iTunes. I don't know if this matters. I've tried re-enconding some of them in iTunes, and the script appears to work perfectly. Any suggestions on what might be giving this error message?


-Gk

Jan 23, 2012 8:13 AM in response to turingtest2

tt2,

My build is the most recent, 10.5.3.3. I thought so my self that the encoder shouldn't matter. Strange that it works for some and not for other files. Interesting enough, if I continue manually cycling through the original scrip (always executing it after the error), adding one file per execution, all files are added back to the library (and those with error, appear without the "count" information)...but then, if I execute the script on these files once again, they all work, with no error...so, maybe it is the way iTunes imported the files to begin with. Well, just some thoughts, anyway. I appreciate your help.

-Gk

Feb 19, 2012 12:11 PM in response to turingtest2

I too am experiencing the same problem GKaram is describing.


The error points to line 382 of your script, which is:


If Instr("itlp.ite.pdf",Ext)=0 Then

.PlayedCount=PC


It appears at the time this is executed, either the iTunes database is locked, the file is locked for writing, or the script has run too fast and the item it's trying to modify isn't "present" to be modified yet. Those are my best guesses. I'm going to try and weed out the last problem by adding a Sleep to your script and see what happens.



What's curious is, I've been using a previous version of your script for years, and have only recently had this issue (and came looking for a new version, stumbling upon this thread). However, your new version has the same issue at the same line of code.. albeit a different line number now since you've added a GUI. Also curious is that the first couple songs seem to work each time I run it. Repeatedly running it over and over does the job, but without play count information as GKaram described.


I think either iTunes has become incompatible somehow (I am on the latest version), or perhaps PC's / SSD's have become fast enough that it's now a timing issue?

Feb 19, 2012 12:15 PM in response to ReanimationXP

I have confirmed this is a timing issue.


Change the following lines starting at line 380, and the script works again. 🙂


TuringTest2, perhaps you can write the script and include a check to see if the item has been written yet before proceeding with modifying its' properties, as to keep it fast?


' Restore extra data for media files only

WScript.Sleep(1000)

If Instr("itlp.ite.pdf",Ext)=0 Then

.PlayedCount=PC

Feb 19, 2012 1:30 PM in response to ReanimationXP

Hi folks, yes I can add some delays into the code. Obviosuly I'm running on some fairly old rubbish. Single core 32-bit XP (ooh maybe it is a multi-threading thing.) In principle the call that adds the track ought to be completed before the call that gets a handle to the newly added track, so the newly added track ought to be in the database before the calls that attempt to update it.


Anyway, I've uploaded a new version of SortDateAdded which I'm hoping will fix things for you. Rather than a single long pause I've restored a few shorter ones that I had previously commented out that relate to the four phases of the operation, saving data, deleting track, adding track and restoring data.


Please let me know how you get on...


tt2

Feb 19, 2012 2:28 PM in response to Mick_M

try opening Itunes.View potions>check the follow boxes. make these boxes are checked, check album artist,check date addded, sort sdded, track nunber.


open a playlist, you can highite the songs snd drag where you want it in the playlist, it should reposition the songs into the order you want, it will also change the track numbers.


Hope this helps,

Peter

Feb 19, 2012 6:05 PM in response to ReanimationXP

VB doesn't do try/catch. There is some cruder stuff you can do with On Error but as stated above the object ought to exist long before the script attempts to update it.


Aha... I think I have it.


The status object exists, but looking hard at the SDK I've seen I should really add in a test to see if iTunes is still busy adding the tracks before attempting to work with the track collection that status will have once InProgress shows up as false...


Do While Status.InProgress

WScript.Sleep 100

Loop


Grrr, that's not it either...


<... Time passes ...>


OK. Horrible error checking kludge implemented and uploaded. Still no real idea why it should be necessary but at least the error materialised at my end for a while so I could see what was happening. I've moved the order around a bit so that the statement that was causing problems happens first, then replaced it with a routine that traps the error and tries up to 10 times at tenth of a second intervals. Seems to work OK for me...


tt2

Sorting by Date Added, but I how can I have songs sorted by track number?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.