Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Create iTunes playlists of rarely-played albums via script Apps
Now and then I like to look back and see which albums I've neglected playing for a while, and listen to them as whole albums. However, as sometimes I like to shuffle by song, it takes a bit of looking to decide which albums haven't been played in a while, and to create a playlist of the whole albums (rather than just the least recently played songs of those albums).

So I wrote this AppleScript to tell me how long it has been since the least recently played song was played, lets me enter how many days back to look, and then finds those albums containing at least one song which hasn't been played in that period of time. This variation of that AppleScript only lists those albums for which half or less of those songs have been played in that period of time (the ratio of 'half' can be easily changed in the script).

The scripts require that you first create a smart playlist called AllMusic of the music files of your library (leaving out all those digital booklets and videos). After that, the scripts are fairly robust, although they probably could be prettier. They create playlists named Dustiest Albums and Dustier Albums, respectively. I hope you find them useful.

[kirkmc adds: There were a couple of issues, notably the fact that the scripts didn't account for tracks that had never been played. So we asked AppleScript wallah Doug Adams to run them through his slicer-and-dicer and tweak the scripts.]
    •    
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[9,391 views]  

Create iTunes playlists of rarely-played albums via script | 21 comments | Create New Account
Click here to return to the 'Create iTunes playlists of rarely-played albums via script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Doesn't work for me :(
Authored by: lullabud on Oct 02, '07 08:29:59AM

I've been looking for something like this! I wanted a way to add *whole albums*, not just the songs from the albums that hadn't been played. This fits the bill perfectly!

...except it's not working. =/ I got one album in my "dustier albums" list and no "dustiest albums". It's possible that the script is choking on non-english characters or some other craziness in my library of like 18,000 songs.

I'd really love for this to work well, I guess I'll check back for updates.



[ Reply to This | # ]
New ones are available.
Authored by: Oops on Oct 05, '07 09:29:26AM
Hi.

I've posted a new version of each which does not have the stated flaws of my original submission and which avoids the use of song names. It is also somewhat more efficient. Perhaps it will work for you. You may find them at:

http://oopsscripts.googlepages.com/

Thank you.

[ Reply to This | # ]
Doesn't work for me :(
Authored by: Oops on Nov 12, '07 02:06:33PM
I now have a new and improved version. Check at

http://oopsscripts.googlepages.com/

Write back, please, about whether or not it now works for you.

Thanks,
Oops

[ Reply to This | # ]
Doesn't work for me :(
Authored by: Oops on Sep 02, '08 09:33:25AM
I've had to put them on a new site:

http://sites.google.com/site/oopscripts/Home

as Google will be soon dropping 'Pages' in favor of 'Sites'. I think the scripts are fairly robust now.

[ Reply to This | # ]
Create iTunes playlists of rarely-played albums via script
Authored by: Dunkin on Oct 02, '07 10:35:52AM

Works great for me on a very small library of music on my work Mac. Thanks.

---
Please, not again.



[ Reply to This | # ]
Create iTunes playlists of rarely-played albums via script
Authored by: deef on Oct 02, '07 04:33:54PM

Looks good but it crashes if you have any missing tracks (with an exclamation point) in your library.



[ Reply to This | # ]
Create iTunes playlists of rarely-played albums via script
Authored by: Oops on Nov 12, '07 02:08:49PM
Hello.

I've a new version which addresses this. If you're interested, please try it and report back. You can get it at:

http://oopsscripts.googlepages.com/

Thanks,
Oops

[ Reply to This | # ]
Create iTunes playlists of rarely-played albums via script
Authored by: Oops on Sep 02, '08 09:34:45AM
I've had to put them on a new site:

http://sites.google.com/site/oopscripts/Home

as Google will be soon dropping 'Pages' in favor of 'Sites'. I think the scripts are fairly robust now.

[ Reply to This | # ]
Create iTunes playlists of rarely-played albums via script
Authored by: soundsgoodtome on Oct 02, '07 08:23:25PM

"So we asked AppleScript wallah Doug Adams to run them through his slicer-and-dicer and tweak the scripts."

Are the posted versions pre-Doug-tweaks or post-Doug-tweaks? It's worded ambiguously.



[ Reply to This | # ]
Create iTunes playlists of rarely-played albums via script
Authored by: kirkmc on Oct 03, '07 01:24:51AM

These are the post-Doug scripts.

Kirk

---
Read my blog: Kirkville -- http://www.mcelhearn.com
Musings, Opinion and Miscellanea, on Macs, iPods and more



[ Reply to This | # ]
Create iTunes playlists of rarely-played albums via script
Authored by: schlepping on Oct 02, '07 09:12:43PM

I haven't looked at the applescript but it seems to me the easiest approach is to create a smart playlist in iTunes and set it up to find your songs play count to whatever you want. I set mine to find play counts < 3. Just takes 10 seconds to setup. Easy.



[ Reply to This | # ]
Create iTunes playlists of rarely-played albums via script
Authored by: soundsgoodtome on Oct 02, '07 09:20:02PM

@schlepping,

True, except the goal was to find entire *albums* containing the neglected tracks. The easy method you described only finds individual songs -- not the complete albums to which they belong. :-)



[ Reply to This | # ]
Create iTunes playlists of rarely-played albums via script
Authored by: soundsgoodtome on Oct 02, '07 09:17:03PM
A bit of perspective might be helpful to some:

I have 6,500 tracks, and "Dustier" found one that hadn't been played for 1,200 days. I entered "1" as the cutoff, switched to Safari, and got lost in other stuff.... Approx. 10 mins. later, the iTunes icon bounced (I'd literally forgotten about the script), and there were 1,300 tracks in the "Dustier" playlist.

So depending upon the amount of data to be processed, this can take several minutes. (Those for whom the scripts don't seem to be working may simply need to allow more time.)

NOTE: Although the new playlist is created immediately, it will be empty! But the script is still working. (I did not observe if the playlist populates gradually, while working, or suddenly, after completion.)

[ Reply to This | # ]
Create iTunes playlists of rarely-played albums via script
Authored by: Oops on Oct 03, '07 06:55:08AM

The playlist populates gradually (in the order they are listed in the Library).

If anyone is wondering whether or not it is failing. Open the script in Script Editor and run it from there. If it bails out, it will give you an error of some kind. If used from the Menu Bar, you won't hear anything about it.

Thank you.



[ Reply to This | # ]
Create iTunes playlists of rarely-played albums via script
Authored by: Oops on Oct 03, '07 06:51:30AM
&Hello. I am the original submitter (who did not have any unplayed songs in his 2200 song library before I went out and bought one). Sorry about the gaff....but if the script were perfect, I wouldn't be named 'Oops'! Thank you to MacOSXHints and Doug Adams for getting a fixed version out there in the first place.

Anyway, here is a script which fixes the problem regarding the unplayed songs and which also makes it so that the user does not have to create any playlists to start with (which was the case of the original unposted script). I stuck to my own less efficient code just because its mine. Also, the one which eventually was posted gets my library age wrong by between 4 and 5 days and I haven't have time to figure out why yet. Also, the scripts which were posted also duplicated videos and digital booklets to the playlist, whereas I just wanted music in the dusty playlist (I don't have time to sit and look at either booklets or videos anyway and if someone has merely an iPod Shuffle like I do, then these are not desired in the playlist). If you want to include these, just remove "and kind contains "audio"" from each statement which has it. This script now eliminates those whose checkbox is unchecked (but this extra can be removed if you remove "and enabled is true"" from every line where it occurs).

If you like the dialog which allows you to delete the script generated playlists, then you can copy that portion of the originally posted script which Doug Adams put in (ince I am 'Oops' it makes me nervous to have 'delete' in any script which I give to someone else). I will later try to remove the use of names, and perhaps that will help when song names have unusual characters (if that indeed is a problem now). I'll also try to see what error I get if there are missing songs (exclamation points in the listing), but for now I would fix the exclamation points. Anyway, here are the updated scripts:


tell application "iTunes"
	set lastTimes to {}
	set longestTime to 0
	set lastTimes to the (played date of every track of library playlist 1 whose played count is greater than 0 and enabled is true and podcast is false and kind contains "audio")
	repeat with i in lastTimes
		set temporalVariable to (current date) - i
		if temporalVariable is greater than longestTime then
			set longestTime to temporalVariable
		end if
	end repeat
	set unplayedSongs to every track of library playlist 1 whose played count is equal to 0 and enabled is true and podcast is false and kind contains ("audio" as list)
	set daysAgo to (longestTime div 86400)
	set overDay to (longestTime / 86400) - daysAgo
	set decimalHours to (overDay * 24)
	set andHours to overDay div (1 / 24)
	set overHours to (overDay * 24) - andHours
	set andMinutes to overHours div (1 / 60)
	if daysAgo is 1 then
		set daysWord to " day"
	else
		set daysWord to " days"
	end if
	if andHours is 1 then
		set hoursWord to " hour"
	else
		set hoursWord to " hours"
	end if
	if andMinutes is 1 then
		set minutesWord to " minute"
	else
		set minutesWord to " minutes"
	end if
	display dialog "The oldest played song was last played " & daysAgo & daysWord & " and " & andHours & hoursWord & "  and " & andMinutes & minutesWord & " ago."
	if unplayedSongs is not {} then
		display dialog "...and some songs have never been played."
	end if
	set daysSincePlayed to ""
	display dialog "Enter the number of days since last played:" default answer the daysSincePlayed
	copy the result as list to {daysSincePlayed, the button_pressed}
	set targetDate to (current date) - daysSincePlayed * days
	set cobwebbedLibrary to the tracks of library playlist 1 whose kind contains "audio" and podcast is false and enabled is true as list
	if user playlist "Dustiest Albums" exists then
		display dialog "Dustiest Albums already exists; I'll add to that playlist new albums."
	else
		make new user playlist with properties {name:"Dustiest Albums", shuffle:false, song repeat:none}
	end if
	set dustiestSong to ""
	set dustiestAlbum to ""
	set dupedAlbums to {} as list
	if the (count of tracks of user playlist "Dustiest Albums") is 0 then
		set alreadylistedDusty to {}
	else
		set alreadylistedDusty to the name of every track of user playlist "Dustiest Albums"
	end if
	repeat with i from 1 to the count of cobwebbedLibrary
		set dustiestSong to item i of cobwebbedLibrary
		if played count of dustiestSong is greater than 0 then
			set playedDate to played date of dustiestSong
			if playedDate is less than targetDate then
				if (album of dustiestSong is not in dupedAlbums) and (name of dustiestSong is not in alreadylistedDusty) then
					set dustiestAlbum to album of dustiestSong
					set dupedAlbums to dupedAlbums & dustiestAlbum
					duplicate (every track of library playlist 1 whose (album is dustiestAlbum and podcast is false and enabled is true and kind contains "audio")) to user playlist "Dustiest Albums"
				end if
			end if
		else
			if (album of dustiestSong is not in dupedAlbums) and (name of dustiestSong is not in alreadylistedDusty) then
				set dustiestAlbum to album of dustiestSong
				set dupedAlbums to dupedAlbums & dustiestAlbum
				duplicate (every track of library playlist 1 whose (album is dustiestAlbum and podcast is false and enabled is true and kind contains "audio")) to user playlist "Dustiest Albums"
			end if
		end if
	end repeat
	display dialog "Transfer Complete"
end tell




Dustier Albums (those with at least half not having been played in x days or some not having ever been played)


tell application "iTunes"
	set lastTimes to {}
	set longestTime to 0
	set lastTimes to the (played date of every track of library playlist 1 whose played count is greater than 0 and enabled is true and podcast is false and kind contains "audio")
	repeat with i in lastTimes
		set temporalVariable to (current date) - i
		if temporalVariable is greater than longestTime then
			set longestTime to temporalVariable
		end if
	end repeat
	set unplayedSongs to every track of library playlist 1 whose played count is equal to 0 and enabled is true and podcast is false and kind contains ("audio" as list)
	set daysAgo to (longestTime div 86400)
	set overDay to (longestTime / 86400) - daysAgo
	set decimalHours to (overDay * 24)
	set andHours to overDay div (1 / 24)
	set overHours to (overDay * 24) - andHours
	set andMinutes to overHours div (1 / 60)
	if daysAgo is 1 then
		set daysWord to " day"
	else
		set daysWord to " days"
	end if
	if andHours is 1 then
		set hoursWord to " hour"
	else
		set hoursWord to " hours"
	end if
	if andMinutes is 1 then
		set minutesWord to " minute"
	else
		set minutesWord to " minutes"
	end if
	display dialog "The oldest song was last played " & daysAgo & daysWord & " and " & andHours & hoursWord & "  and " & andMinutes & minutesWord & " ago."
	if unplayedSongs is not {} then
		display dialog "...and some songs have never been played."
	end if
	set daysSincePlayed to ""
	display dialog "Enter the number of days since last played:" default answer the daysSincePlayed
	copy the result as list to {daysSincePlayed, the button_pressed}
	set targetDate to (current date) - daysSincePlayed * days
	set cobwebbedLibrary to (every track of library playlist 1 whose kind contains "audio" and podcast is false and enabled is true) as list
	if user playlist "Dustier Albums" exists then
		display dialog "Dustier Albums already exists; I'll add to that playlist new albums."
	else
		make new user playlist with properties {name:"Dustier Albums", shuffle:false, song repeat:none}
	end if
	set dustiestSong to ""
	set dustiestAlbum to ""
	set dupedAlbums to {} as list
	if the (count of tracks of user playlist "Dustier Albums") is 0 then
		set alreadylistedDusty to {}
	else
		set alreadylistedDusty to the name of every track of user playlist "Dustier Albums"
	end if
	repeat with i from 1 to the count of cobwebbedLibrary
		set dustiestSong to item i of cobwebbedLibrary
		if played count of dustiestSong is greater than 0 then
			set playedDate to played date of dustiestSong
			if playedDate is less than targetDate then
				if (album of dustiestSong is not in dupedAlbums) and (name of dustiestSong is not in alreadylistedDusty) then
					set dustiestAlbum to album of dustiestSong
					set oldCount to 0
					set albumSize to 0
					set songNames to (every track of library playlist 1 whose album is dustiestAlbum)
					repeat with eachSong in songNames
						set albumSize to albumSize + 1
						set playedDate to the played date of eachSong
						if playedDate is less than or equal to targetDate then
							set oldCount to oldCount + 1
						end if
					end repeat
					if ((2 * oldCount) div albumSize) is greater than or equal to 1 then
						set dupedAlbums to dupedAlbums & dustiestAlbum
						duplicate (every track of library playlist 1 whose (album is dustiestAlbum and kind contains "audio" and enabled is true and podcast is false)) to user playlist "Dustier Albums"
					end if
				end if
			end if
		else
			if (album of dustiestSong is not in dupedAlbums) and (name of dustiestSong is not in alreadylistedDusty) then
				set dustiestAlbum to album of dustiestSong
				set dupedAlbums to dupedAlbums & dustiestAlbum
				duplicate (every track of library playlist 1 whose (album is dustiestAlbum and podcast is false and enabled is true and kind contains "audio")) to user playlist "Dustier Albums"
			end if
		end if
	end repeat
	display dialog "Transfer Complete"
end tell


[ Reply to This | # ]
Library age difference is because of videos
Authored by: Oops on Oct 03, '07 07:18:57AM

The Library age is different between these two scripts because the adjustment by Doug Adams includes the ages of videos and mine just includes the ages of songs. Removal of "and kind includes "audio"" from any line where it occurs in my script above will include videos and digital booklets in the playlist and will calculate the age accordingly.



[ Reply to This | # ]
New-and-improved versions are available.
Authored by: Oops on Oct 05, '07 09:31:18AM
Hi.

I've posted a new version of each which does not have the stated flaws of my original submission and which avoids the use of song names. It is also somewhat more efficient. You may find them at:

http://oopsscripts.googlepages.com/

Thank you.

[ Reply to This | # ]
New-and-improved versions are available.
Authored by: Oops on Nov 12, '07 02:11:21PM

Newer versions are now available which address flaws mentioned here.



[ Reply to This | # ]
Video tutorial on smart playlists
Authored by: 123Hints on Apr 07, '08 04:11:08PM
There is a video screen cast on how-to create screencasts at http://www.123hints.com or you can download it directly at http://media.libsyn.com/media/newcommunciations/Smart_Playlists_in_iTunes.m4v

I love smart playlists!

[ Reply to This | # ]
New-and-improved versions are available.
Authored by: Oops on Sep 02, '08 09:36:42AM
I've had to put them on a new site:

http://sites.google.com/site/oopscripts/Home

as Google will be soon dropping 'Pages' in favor of 'Sites'. I think the scripts are fairly robust now.

[ Reply to This | # ]
Create iTunes playlists of rarely-played albums via script
Authored by: dp6ai on Dec 05, '11 02:27:00AM

Should these scripts work in iTunes 10? (10.5.1)
I'm getting the following error:

error "Can’t make missing value into type number or date." number -1700 from missing value to number or date

thanks in advance.

DP



[ Reply to This | # ]