copying metadata from itunes song to another

Hi!

I’m new to this forum as I’m new to AppleScript. This is my first try with AppleScript. I’ve searched for it in these forums, in Google… nothing. Here is my problem: iTunes returns “Unknown object type” when I try to copy the “date added” metadata of a song to one another. Here is my code:


tell application "iTunes"
	if selection is not {} then
		repeat with newItem in selection
			set newArtist to artist of newItem
			set newAlbum to album of newItem
			set newName to name of newItem
			
			set oldItem to item 1 of (tracks of source "MyPCLibrary" whose artist is newArtist and album is newAlbum and name is newName)
			
			-- oldItem, here, is rightly pointing to desired song
			
			set date added of newItem to (get date added of oldItem)
		end repeat
	end if
end tell

I’ve tried this code too (note the “get” before selection repeat and another “get” before getting the shared track)


tell application "iTunes"
	if selection is not {} then
		repeat with newItem in (get selection)
			set newArtist to artist of newItem
			set newAlbum to album of newItem
			set newName to name of newItem
			
			set oldItem to item 1 of (get tracks of source "MyPCLibrary" whose artist is newArtist and album is newAlbum and name is newName)
			
			-- oldItem, here, is rightly pointing to desired song
			
			set date added of newItem to (get date added of oldItem)
		end repeat
	end if
end tell

Also tried to copy “date added” from another song in the same local library (library playlist 1) but didn’t worked. And, also, I’ve tried with any other metadata (such as “played count”, or any other) but did’nt worked. The unique way it’s working is setting manually a value like: “set date added of newItem to current date”

Anyone knows what I’m doing wrong?

Hi,

from the iTunes dictionary:

date added get date the date the track was added to the playlist

date added is read only

I saw that, but following code is working fine:


set date added of newItem to current date

So, I don’t understand why in the dictionary says R/O… Also, I tried with other params like “played count”, “name”, “album” or “artist” whose are writeable and didn’t work…

Ups… Please, can any moderator change/correct the title of this topic replacing “copyind” for “copying”? Thanks :slight_smile:

I don’t understand this contradiction, Writing the date added property does not work, unless Apple has changed it in Snow Leopard.

The problem to change any property depends on the list form.
NewItem is a reference to a list item not the item itself.
To change a list element you must dereference it


.
set date added of contents of newItem to (get date added of oldItem)
.

Sure thing! :slight_smile:

StefanK: I tried what you suggested (adding “contents of”) and iTunes is returng the same error… “Unkown object type”. Also for any other param such as “artist”… Any other idea?

Craig Williams: Thanks! :slight_smile:


set oldItem to item 1 of (tracks of source "MyPCLibrary" whose artist is newArtist and album is newAlbum and name is newName)

this line doesn’t retrieve reliably the corresponding track, because item 1 could be the item itself.
Filtering the database ID avoids the problem


tell application "iTunes"
	if selection is not {} then
		repeat with newItem in selection
			set {artist:newArtist, album:newAlbum, name:newName, database ID:databaseID} to newItem
			set oldItem to (1st track of source "MyPCLibrary" whose artist is newArtist and album is newAlbum and name is newName and database ID is not databaseID)
			
			set year of contents of newItem to (get year of oldItem)
		end repeat
	end if
end tell

Finally I get this working! Thanks to your script, StefanK. Now the “problem” is that “date added” is really read-only… Now, at least, I can get all the other metadata. Thanks again! :slight_smile:

I don’t think so, but… If anyone else knows any other way to change this parameter (date added)…???

there is only ONE way to change the date added property.
¢ Export the tracks in a playlist as text file.
¢ Change the system date to the desired one.
¢ Reimport the tracks
¢ Reset the date

Yeah… That could be a way, but… this issue began when trying to move the entire iTunes Library from my old PC to my new iMac… I like to have all music perfectly catalogued, I have some playlists depending on “date added” parameter, which contains dates since many years ago to last week… Now, all this information is lost… And of course, I will not change the system date thousands and thousands of times to import each song again… However, thanks for your help again. I’ve given up to recover this information as I see there’s no human way… :frowning:

One more thing…
If any Apple worker never reads this, if never Steve Jobs read this (jah… absurd…), please, make it easier to move iTunes Libraries trough computers without losing tonnes of information, without losing hours and hours and hours and hours inverted trying to have a fine catalogued music collection. Just for a reason, it’s frustrating when you lose it in a few seconds…!

The only information you loose is the date added information, everything else will be kept.
You can copy a whole iTunes Music Library by copying the folder iTunes which includes the database files.
On the target computer launch iTunes with option key and choose the iTunes folder. This preserves also the date added information.

But I don’t know, if this works also between PC and Mac, but who needs a PC. :wink: