iLounge 2013 iPhone + iPod Buyers' Guide
Become a member of the iLounge Forums. Register Now!
To start viewing messages, select the forum that you want to visit from the selection below.
If this is your first visit, be sure to check out the Forum FAQ and Forum Policy.

Topic: Applescript to add "Track Count" to imported tracks???

Reply Thread Tools Topic Search
 
Old 07-30-2009, 02:44 PM
#1
 
Freshman Lounger
 
Join Date: Nov 2008
Posts: 8
Applescript to add "Track Count" to imported tracks???

I've imported about 500 tracks each of which are correctly tagged for Artist, Album and Track Number. However none of them have the Track Count. I know I can select each album, do the Get Info and add this by hand but I hope someone has a script to do this.

I've looked through Doug's AppleScript for iTunes, iPodLounge, and John Eustacescrubb's items an don't find what I need.

Doug has "Set Track Count V1.0" but one still has to manually type the number of track as part of executing the script.

I've search iLounge's AppleScripts for iTunes (Mac) forums for "Track Count" and still get no hits.

Am I simply not finding the right matches to my search of does such a Track Count script not exisit?

It should be possible (for an AppleScript guru) to count the track in an album and then assign the track count to the correct tag.

All suggestions are appreciated. But I;m not a programmer.

Thanks!
Bill
quattleb is offline  
Share on TwitterShare on FacebookDigg this Post!Google Bookmark this Post!
Reply With Quote

Join the iLounge Community and the ad above will disappear.

Old 07-30-2009, 04:23 PM
#2
 
Veteran Lounger
 
S2_Mac's Avatar
 
Join Date: Oct 2006
Location: About 3 feet in front of the monitor
Posts: 4,878

I had to think about this issue when making my Play This Track's Album script; it's a tough problem to solve in the general case; there's no easy-to-read source of reliable track counts online, and there's no way to be "correct" when relying solely on the user's data....

With that said, try this script on a few tracks (just a few, to find out how you like it ;-); it should do what you what you want. But be careful, because this script does what you want ;-)

Works like this:
1) Select a bunch of tracks; any album represented in the selection will have all of its tracks' Track Count field updated
2) Engage the script. You will get no dialogs except for when one or more tracks from the album have a higher Track Count than the highest Track Number of any of the album's tracks. In that case you will be asked which number to use -- the highest Track Number, or the highest Track Count. (You should usually choose the Track Count.)
3) Each track of every album represented in the selection will be examined for its Track Number and its Track Count. The script will use the highest Track Number as the new Track Count for all tracks in the album, except for the special case described in 2).

Just to be clear -- the script doesn't count tracks (since users may have dupes of tracks, for instance the same song in different formats); it looks at all the Track Number tags for the album and uses the highest Track Number as the new Track Count. If you can live with that, then here ya go:
Code:
-- NOTE:
-- the iTunes display MUST NOT be sorted by Track Count
-- if 'smart', the displayed playlist MUST NOT use Track Count as one of its criteria

tell application "iTunes"
	set sel to a reference to the selection
	set seen to {}
	repeat with i from 1 to count of sel
		set cur_album to album of item i of sel
		if cur_album is not in seen then
			set cur_album_tracks to (every track of library playlist 1 whose album is cur_album)
			set high_track to 0
			set high_track_count to 0
			repeat with trak in cur_album_tracks
				set t to track number of trak
				if t > high_track then set high_track to t
				set t to track count of trak
				if t > high_track_count then set high_track_count to t
			end repeat
			if high_track_count > high_track then
				set high_track_count to button returned of (display dialog "At least one track in the album has a Track Count that's greater than the highest Track Number." & return & return & "Use the highest Track Count number (" & high_track_count & "), or use the highest Track Number (" & high_track & ")?" & return & return & "(Using the highest Track Count is p'bly the best way to go.)" buttons {"Cancel", high_track as string, high_track_count as string} default button 3)
			end if
			repeat with trak in cur_album_tracks
				set track count of trak to high_track_count
			end repeat
			set end of seen to cur_album
		end if
	end repeat
end tell
To use, copy the code into a new Script Editor window; save the script as "Best Guess Track Count.scpt", then place it in ~/Library/iTunes/Scripts. To run the script, select tracks from any iTunes listing (noting the exclusions listed at the top of the code) and then select the script from the iTunes "Scripts" menu. (If there is no "Scripts" or "iTunes" folders in ~/Library, just go ahead and create them.) Or, you can just run it from Script Editor by clicking the green Run button or pressing Cmd-R
S2_Mac is offline  
Share on TwitterShare on FacebookDigg this Post!Google Bookmark this Post!
Reply With Quote
Old 07-30-2009, 06:09 PM
#3
 
Freshman Lounger
 
Join Date: Nov 2008
Posts: 8

S2-Mac - nice idea and certainly will do the trick. However seems to be a bug. I did the copy/paste and created the script. Selected a single album worth of track in iTunes and then ran the scrip from the script editor. There is no change to the Track Count of the tracks. Looking at the code and the Event Log shows that each time through the loop "t" gets set to the value of an existing Track Count (which is ZERO since these tracks do not have a Track Count). Then when the loop exist each track Id has the track count set to high_track_count which is 0.

When I comment out the line "set t to track count of trak" it appears to work correctly.

Does this sound right (like a typo in the code?)

thanks again
Bill
quattleb is offline  
Share on TwitterShare on FacebookDigg this Post!Google Bookmark this Post!
Reply With Quote
Old 07-31-2009, 08:30 AM
#4
 
Veteran Lounger
 
S2_Mac's Avatar
 
Join Date: Oct 2006
Location: About 3 feet in front of the monitor
Posts: 4,878

Not a typo; I just forgot ;-) Here's a fixed version, with added safeguard against tracks that have no Album tag. (BTW, it's sufficient to select only one track from an album to set the Track Count for all the album's tracks.)
Code:
-- NOTE:
-- the iTunes display MUST NOT be sorted by Track Count
-- if 'smart', the displayed playlist MUST NOT use Track Count as one of its criteria

tell application "iTunes"
	set sel to a reference to the selection
	set seen to {}
	repeat with i from 1 to count of sel
		set cur_album to album of item i of sel
		if cur_album is not "" then
			if cur_album is not in seen then
				set cur_album_tracks to (every track of library playlist 1 whose album is cur_album)
				set high_track to 0
				set high_track_count to 0
				repeat with trak in cur_album_tracks
					set t to track number of trak
					if t > high_track then set high_track to t
					set t to track count of trak
					if t > high_track_count then set high_track_count to t
				end repeat
				if high_track_count > high_track then
					set high_track_count to button returned of (display dialog "At least one track in the album has a Track Count that's greater than the highest Track Number." & return & return & "Use the highest Track Count number (" & high_track_count & "), or use the highest Track Number (" & high_track & ")?" & return & return & "(Using the highest Track Count is p'bly the best way to go.)" buttons {"Cancel", high_track as string, high_track_count as string} default button 3)
				else
					set high_track_count to high_track
				end if
				repeat with trak in cur_album_tracks
					set track count of trak to high_track_count
				end repeat
				set end of seen to cur_album
			end if
		else
			display dialog "The track “" & name of item i of sel & "” has no Album tag; skipping this track." buttons {"OK"} default button 1 giving up after 1
		end if
	end repeat
end tell
S2_Mac is offline  
Share on TwitterShare on FacebookDigg this Post!Google Bookmark this Post!
Reply With Quote
Old 07-31-2009, 10:00 AM
#5
 
Freshman Lounger
 
Join Date: Nov 2008
Posts: 8

Better and better! Selecting only track 1 from each album seems about 30% faster than selecting the entire list of tracks.

I thought I'd be smart and "help myself" by finding some way to set the sort order as part of the script. This way I could sort by track number, select only track #1 for each and the run the scrip. But looking through the Library of iTunes script commands I see no way to control the view (of the sort column) of the playlist that has tracks selected. If that is the case I'll have to remember to switch back to something like sort by Artist after I select all the #1 tracks.

thanks much
Bill
quattleb is offline  
Share on TwitterShare on FacebookDigg this Post!Google Bookmark this Post!
Reply With Quote
Old 07-31-2009, 10:03 AM
#6
 
Freshman Lounger
 
Join Date: Nov 2008
Posts: 8

Hummm - perhaps I am mis-reading the "must not be sorted by Track Count." I don't see a way to sort by COUNT - only try Track #. So I had assumed that is what was meant. So I tested a small group - selecting them when sorted by Track # (selecting only track #1 for each) and everything seems to work fine.

Am I overlooking some column that can be sorted by track COUNT?

Bill
quattleb is offline  
Share on TwitterShare on FacebookDigg this Post!Google Bookmark this Post!
Reply With Quote
Old 07-31-2009, 01:11 PM
#7
 
Veteran Lounger
 
S2_Mac's Avatar
 
Join Date: Oct 2006
Location: About 3 feet in front of the monitor
Posts: 4,878

Am I overlooking some column that can be sorted by track COUNT?

Nope ;-) Since I was in a hurry and too lazy to add code to get/set/restore 'fixed indexing', I just noted the situations where sort criteria could mess things up; doesn't mean those criteria can actually be used....<g>

Don't worry about selecting "extra" tracks -- if the script has already processed a track's allbum it just passes that track by; the time spent is under a thousandth of a second.
S2_Mac is offline  
Share on TwitterShare on FacebookDigg this Post!Google Bookmark this Post!
Reply With Quote
Old 01-06-2010, 11:58 AM
#8
 
Freshman Lounger
 
Join Date: Nov 2008
Posts: 8
Track Count script working "too well!?!?!"

Hello S2_Mac - I've been using your Track Count script for many months and really find it a time saver.

However... (ah yes) - it is doing its job too enthusiastically! It has taken me a while to notice and confirm but rather than only looking at the albums I have selected in a playlist it is looking at my entire Library to find albums that match AND changing ALL albums that match to the highest track count.

For example - say I import Band#1s "Greatest Hits", create a Playlist with only it, select its tracks in the playlist and execute the script.

At the same time I have Band#2s "Greatest Hits" in my Library. Well, since the album names match the script determines the highest track count between them and applies that number to BOTH "Greatest Hits" albums.

In my case I've actually got 8 albums titled "Greatest Hits", 25 is the highest track count and all 8 albums got set to a TC of 25.

Of course there are other identical album names in the Library.

So is there a way to force the script to only look and only change the tracks I have selected?

thanks much
Bill
quattleb is offline  
Share on TwitterShare on FacebookDigg this Post!Google Bookmark this Post!
Reply With Quote

Topic: Applescript to add "Track Count" to imported tracks???

Reply Thread Tools Topic Search

Become a member of the iLounge Forums. Register Now!
To start viewing messages, select the forum that you want to visit from the selection below.
If this is your first visit, be sure to check out the Forum FAQ and Forum Policy.
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginners Guide. Copying an Audio CD to a Bookmarking iPod File. All iTunes process. robert Books and Spoken Word 78 09-17-2008 11:01 PM
Basis of a "Script to add placeholder/wishlist item/dummy track to a playlist" i5m AppleScripts for iTunes (Mac) 9 11-04-2004 04:05 PM
My Reccommended Albums(And yours as well, if you add them!) Pt.2 BoomAM Music & Audio 56 09-23-2004 04:22 AM
Add Selected Remote Tracks: can it actually COPY the song file? darkside AppleScripts for iTunes (Mac) 2 04-27-2004 04:48 PM
How do I add new tracks to iTunes that I've added to the storage drive? Mr Jolly iTunes + Related Mac/PC Applications 11 03-16-2004 12:59 PM




View iLounge History. Read our old Forums Archive (2001-2003)
All times are GMT -4. The time now is 12:25 PM.


Shop for Accessories: Cases, speakers, chargers, etc.