Sort songs by Date Created Script

GO TO ADMIN PANEL > ADD-ONS AND INSTALL VERTIFORO SIDEBAR TO SEE FORUMS AND SIDEBAR

dbetanc

New member
Joined
Aug 3, 2003
Messages
4
Points
0
Hello Again,

I'd like to know if there is a way to organize songs by Date Created. iTunes only has Date Added, and Date Modified, but it does not show Date Created.

I'm a song writer, and I have a big catalog with my own compositions, and i'd like to be able to sort them by creation date.

Thanks,

Daniel
 
Joined
Jul 1, 2003
Messages
705
Points
0
Location
Providence, RI, USA
Website
dougscripts.com
You cannot change the sort column with AppleScript. However I would suggest sorting by "Date Added", since that's the closest iTune will ever get to "Date Created"

However, you could write a script that got the date created from the file in the Finder and pasted it to Comments; then, you could sort by Comments.
 

dbetanc

New member
Joined
Aug 3, 2003
Messages
4
Points
0
Thanks Doug, but, how do I do that? I'm really not that good with scripts.

Thanks!

Daniel
 
Joined
Jul 1, 2003
Messages
705
Points
0
Location
Providence, RI, USA
Website
dougscripts.com
Daniel,

I realise you may not want this script as it is, but I thought others would be interested. I've been toying with this:

Code:
[SIZE=1]tell application "iTunes"
	set p to (get view of front window)
	if selection is not {} then
		copy selection to sel
	else
		copy every track of p to sel
	end if
	
	repeat with t in sel
		if class of t is file track then
			tell t
				try
					copy my get_info_of(location) to comment
				end try
			end tell
		end if
	end repeat
end tell

to get_info_of(loc)
	tell application "Finder"
		try
			copy creation date of (get info for loc) to d
		end try
	end tell
	return d
end getInfoOf[/SIZE]
This script copies the "Date Created" string to each track's comment. This string looks like this:

Code:
Tuesday, August 15, 2000 5:57:46 AM
But here's the deal: it's a string, not a date, so that when you sort by comments, it sorts by alphabetical order (Fridays followed by Mondays followed by Saturday, etcetera).

What will have to be done is convert the date string to year-month-day-time, perhaps like 2000081505:57:46AM. This is fairly simple, but I thought others may want to see this in case they wanted to play with it too. Perhaps there are other date/time formats that are preferable.
 
Joined
Jul 1, 2003
Messages
705
Points
0
Location
Providence, RI, USA
Website
dougscripts.com
Here 'tis

OK. This is improved somewhat. It will put a string like this into the comments of each selected track:
Code:
2002060308:52:08PM - Monday, June 3, 2002 8:52:08 PM
So not only will it sort properly, but you can see the date in case you can't read numbers that quickly :)

Here's the code. It works on the selected tracks, or, if no selection, it will assume you want to use all the tracks of the selected playlist. This is posted at the site as File Creation Date to Comments . However, you can copy this to Script Editor and Save it in home > Library > iTunes > Scripts and it will appear in iTunes' Scripts Menu.

Code:
[SIZE=1]property mos : {January, February, March, April, May, June, July, August, September, October, November, December}
tell application "iTunes"
	set p to view of front window
	if selection is not {} then
		copy selection to sel
	else
		copy every track of p to sel
	end if
	set ofx to fixed indexing
	set fixed indexing to true
	repeat with t in sel
		if class of t is file track then
			tell t
				try
					copy my get_info_of(location) to comment
				end try
			end tell
		end if
	end repeat
	set fixed indexing to ofx
	display dialog "I've done all I can do!" buttons {"Thanks"} default button 1 with icon 1
end tell

to get_info_of(l)
	tell application "Finder"
		try
			set inf to (get info for l)
		on error
			return
		end try
	end tell
	set d to (get creation date of inf)
	set myy to (year of d) as string
	repeat with i from 1 to 12
		if (item i of mos) is (month of d) then
			set mym to (i as string)
			if mym as number is less than 10 then set mym to "0" & mym
			exit repeat
		end if
	end repeat
	set myD to (day of d) as string
	if myD as number is less than 10 then set myD to "0" & myD
	set myT to time string of d
	if character 2 of myT is ":" then set myT to "0" & myT
	set myT to (((characters 1 through -4 of myT) as string) & (characters -2 through -1 of myT) as string)
	return ((myy & mym & myD & myT) as string) & " - " & d as string
end get_info_of[/SIZE]
 
Last edited:

dbetanc

New member
Joined
Aug 3, 2003
Messages
4
Points
0
GREAT!! It works fantastic!!! Thank you soo much. ...mmmm and, one more thing?

Have you read my other post asking if there is a script that relinks files with the exclamation mark? I have a bunch of files that iTunes forgot where they are, and they are inside the iTunes folder for sure.
 
Joined
Jul 1, 2003
Messages
705
Points
0
Location
Providence, RI, USA
Website
dougscripts.com
Have you read my other post asking if there is a script that relinks files with the exclamation mark?
This is rather difficult to script. See, the reason that those "dead tracks" are believed to be dead is that iTunes doesn't know where they are; if Tunes doesn't know where they are, then it will be difficult for a script to track them down.

However, for users who let iTunes keep their Music folder organized, it may be possible to create a script that looks in the Music folder : Artist name folder : Album name folder for files that have the same names as the track. (I recently posted some work which tried to locate the Music folder via the iTunes Music Library.xml file -- see the post entitled "Lab Rats Wanted") I know on my system this would probably fail more than half the time, since I do a lot of editing of track info, and do not let iTunes organize things.
 
Top