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: Updating Last Played field after iPod Shuffle sync

Reply Thread Tools Topic Search
 
Old 02-11-2005, 05:12 AM
#1
 
Freshman Lounger
 
Join Date: Aug 2003
Posts: 8
Updating Last Played field after iPod Shuffle sync

Please choose the appropriate forum for this topic. Thank you. My two iPod strategy is entirely justified by the fact that the shuffle prompts me to re-explore the dark and dingy corners of my music collection. Anyone that is saying "but you can create the same kind of playlist on your main iPod" might as well stop because I have my fingers in my ears.

The big problem with my justification is that without a Last Played timestamp, finding those gems that were re-discovered on a bus is tricky. I am happy to stamp the songs played on the Shuffle with the time of sync, so I have had a go at some Applescript to do just this. It is rather a hack, very slow, and I would really appreciate some feedback to make it smooth and robust!

First of all, I need to take a dump of the play count info before the Shuffle goes anywhere near the Mac...


Code:
property ShuffleTrax : "iPod Shuffle"

tell application "iTunes"
	set myPlaylist to playlist ShuffleTrax
	set theFile to open for access file "Shuffle Playlist" with write permission
	set eof theFile to 0
	repeat with aTrack in (get every track of myPlaylist)
		set dbID to database ID of aTrack
		set pc to get played count of aTrack
		set nm to get name of aTrack as string
		write {dbID, pc, nm} to theFile as list
	end repeat
	
	close access theFile
	
end tell
...then I connect my Shuffle, let it do its sync stuff, and then run the following S---L---O---W script. I just hope they never make a 10gb Shuffle, or at least not until I've learnt how to do this properly...

Code:
set theFile to open for access file "Shuffle Playlist" with write permission
set cd to (get current date)
try
	repeat
		set theData to read theFile as list
		set dbID to item 1 of theData
		set pc to item 2 of theData
		set nm to item 3 of theData
		tell application "iTunes"
			set thetrack to some track of playlist 1 whose database ID is dbID
			set theArtist to the artist of thetrack
			set thePlayCount to the played count of thetrack
			if thePlayCount is greater than pc then
				display dialog nm & " - " & theArtist & " (was " & pc & " - now " & thePlayCount & ")" buttons ("OK") default button 1
				set played date of thetrack to cd
			end if
		end tell
	end repeat
on error
	close access theFile
	display dialog "Done" buttons ("OK") default button 1
end try
All suggestions gratefully received.

Thanks
Alastair.
amjbrown is offline  
Reply With Quote

Join the iLounge Community and the ad above will disappear.

Old 02-13-2005, 01:19 PM
#2
 
Senior Lounger
 
Join Date: May 2003
Location: London, UK
Posts: 188

Looks good!

I'll try it out on my pb asap.

I dont really have any suggestions as im not much good with apple script, so cant help there!

is there a way of storing the playcount in the comments field tho? (then just go through the ipod shuffle playlist before refilling, and update the played date from there?)
davebach172 is offline  
Reply With Quote
Old 02-13-2005, 05:25 PM
#3
 
Freshman Lounger
 
Join Date: Aug 2003
Posts: 8

It would be much quicker if I made use of the comments field. However, some people might already use that for something else.

There are lots of posts about the speed of accessing tracks by their Database ID - but I don't know enough about Applescript to really understand them. Hpopefully someone with a Shuffle might know more.

What I really want to do is find a way of automating the whole process so when the Shuffle is connected, the old play count is captured, the Shuffle synced, and then the Played Date adjusted. There is an app called iPod launcher, but I don't thing you can specify different actions for different iPods. haven't had chance to really explore it.
amjbrown is offline  
Reply With Quote
Old 02-15-2005, 06:24 PM
#4
 
Pro Lounger
 
Join Date: Jan 2005
Location: internal exile
Posts: 858

This is a very cool thing. And you're right -- it's very slow. It's such a useful function, though. Thank you for sharing the results of your labor with us!
wyneken is offline  
Reply With Quote
Old 02-16-2005, 04:00 AM
#5
 
Freshman Lounger
 
Join Date: Feb 2005
Posts: 2

I'm pretty new to using AppleScripts for anything, but, when I tried to install the above code and run it I got:

Can't get <<class cPly>> "iPod Shuffle" of aplication "iTunes".

I'm no programer. What does that mean?

It's certainly a very important script. Hopefully apple will include something in the next iTunes update to do the job.

I'm trying to use Smart Playlists to keep songs recycling through my shuffle based on not playing tracks with a recent Last Played date. The lack of last played date stamping by the shuffle certainly does screw up the balance of the system.
wheels00 is offline  
Reply With Quote
Old 02-16-2005, 05:32 AM
#6
 
Freshman Lounger
 
Join Date: Aug 2003
Posts: 8

Quote:
Originally posted by wheels00
I'm pretty new to using AppleScripts for anything, but, when I tried to install the above code and run it I got:

Can't get <<class cPly>> "iPod Shuffle" of aplication "iTunes".
What's your Shuffle called?

If it is Wheels00's Shuffle then you would change the first line to...

Code:
property ShuffleTrax : "Wheels00's Shuffle"
However, I cannot re-create your error by changing the property value. I just get can't get Play List xxxx.
amjbrown is offline  
Reply With Quote
Old 02-16-2005, 05:40 AM
#7
 
Freshman Lounger
 
Join Date: Aug 2003
Posts: 8

Quote:
Originally posted by wheels00
I'm pretty new to using AppleScripts for anything, but, when I tried to install the above code and run it I got:

Can't get <<class cPly>> "iPod Shuffle" of aplication "iTunes".
Sorry...a bit more research would have revealed the answer.

I get the same error message if the Shuffle is disconnected and I haven't checked "Keep the iPod in the source list" in the options tab.

Try that, it should work fine then.

Thanks
Alastair.
amjbrown is offline  
Reply With Quote
Old 02-16-2005, 07:35 PM
#8
 
Freshman Lounger
 
Join Date: Feb 2005
Posts: 2

ahhhhhhhhhhhhhhhhh!

That makes so much sense.

it works wonderfully now.

Thanks
wheels00 is offline  
Reply With Quote
Old 02-28-2005, 08:17 AM
#9
 
Pro Lounger
 
Join Date: Jan 2005
Location: internal exile
Posts: 858

Can this script be modified so that it doesn't need continual attention, in the form of clicking "OK" in the dialog box whenever an update is made?

Thanks.
wyneken is offline  
Reply With Quote
Old 02-28-2005, 08:27 AM
#10
 
Freshman Lounger
 
Join Date: Aug 2003
Posts: 8

Easy...

just knock out the line that begins...

Code:
display dialog nm " - " & theA...
either delete it, or comment it out by prefixing the line with...

Code:
--
I only put that in to check it hadn't taken leave of its senses - I am new to this business! I did then like being reminded what I had heard, but I have now changed it so that a playlist is created containing all the tracks that just synced.

Thanks
Alastair.
amjbrown is offline  
Reply With Quote
Old 03-11-2005, 06:59 AM
#11
 
Pro Lounger
 
Join Date: Jan 2005
Location: internal exile
Posts: 858

Alastair, I want to thank you again for sharing this script. It has become an indispensible part of my shuffle experience.

You wrote:

Quote:
Originally posted by amjbrown
... I have now changed it so that a playlist is created containing all the tracks that just synced.
Would you mind posting this revised script, for the benefit of us non-script-savvy types? This does sound like a better way of doing things.

Thanks again
/stav
wyneken is offline  
Reply With Quote
Old 03-11-2005, 11:53 AM
#12
 
Freshman Lounger
 
Join Date: Aug 2003
Posts: 8

You're very welcome!!

File creation script stays the same.

The second script becomes...

Code:
set theFile to open for access file "Shuffle Playlist" with write permission
set cd to (get current date)
set iJustHeardPL to "iShuffle " & cd as string
tell application "iTunes"
	if not (exists playlist iJustHeardPL) then
		make new playlist with properties {name:iJustHeardPL}
	else
		delete every track of playlist iJustHeardPL
	end if
	try
		repeat
			set theData to read theFile as list
			set dbID to item 1 of theData
			set pc to item 2 of theData
			set nm to item 3 of theData
			set thetrack to some track of playlist 1 whose database ID is dbID
			set theArtist to the artist of thetrack
			set thePlayCount to the played count of thetrack
			if thePlayCount is greater than pc then
				set played date of thetrack to cd
				duplicate thetrack to playlist iJustHeardPL
			end if
		end repeat
		close access theFile
	on error
		close access theFile
		display dialog "Done" buttons ("OK") default button 1
	end try
end tell
I still hoping some script guru with a shuffle habit can give me some tips on speeding the whole thing up...

Thanks
Alastair
amjbrown is offline  
Reply With Quote
Old 03-26-2005, 05:25 AM
#13
 
Freshman Lounger
 
Join Date: Mar 2005
Posts: 1

I've now written a script that uses the "grouping" field for storing the played count. So if you use the "grouping" field you should not use this script.

You should run the script after you've inserted the iPod Shuffle and also after you've add new music to the iPod Shuffle.

Code:
set iPodShuffleName to "Shuffle Me Baby" as string -- The iPodShuffle name
set iShuffleUpdatePlaylist to "iShuffleUpdateThingi" as string -- Playlist to save info in. You should not change or edit in the playlist.

tell application "iTunes"
	if not (exists playlist iShuffleUpdatePlaylist) then
		make new playlist with properties {name:iShuffleUpdatePlaylist}
	else
		repeat with each_t in every track of playlist iShuffleUpdatePlaylist
			set played_count to played count of each_t as string
			set played_count_before to grouping of each_t as string
			
			if not played_count is equal to played_count_before and not played_count_before is "" and not played_count_before is equal to "0" then
				set played date of each_t to get current date
			end if
		end repeat
		
		delete every track of playlist iShuffleUpdatePlaylist
	end if
	
	repeat with each_t in every track of playlist iPodShuffleName
		set database_id to database ID of each_t
		set a_tracker to duplicate each_t to playlist iShuffleUpdatePlaylist
		set played_count to played count of a_tracker as string
		set a_tracker's grouping to played_count
	end repeat
end tell
ahlstrominfo is offline  
Reply With Quote

Topic: Updating Last Played field after iPod Shuffle sync

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





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


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