Creating Duplicate Tracks


I have a script which simulates the DJ broadcasts from the video game Fallout 3 and inserts them into the playlist I sync with my iPod. Unfortunately, this means there are quite a few duplicate tracks which seems to mess up syncing the iPod’s play and skip count info (which I require for a different system I wrote a while ago). The simplest way to remedy this since the tracks are very tiny is to duplicate them and have my script index the names accordingly while assembling the playlist (already tested it and the approach works). Other solution suggestions are, of course, welcome.


Is there a way to create duplicate tracks using Applescript? I need to generate a bunch and could do so manually as it’s a one time thing, but I’d rather not have to. My attempts to search on this were thwarted by all the pages talking about doing the reverse (ie removing duplicates). Thanks.

Hi maxim,

I don’t know why but I’ve read your post several times and don’t understand what you are trying to do.

Are you trying to duplicate tracks in iTune? Still confused.


Yes, I’m trying to create multiple identical tracks (although I’ll give them different names).

I need it to work around an iPod bug with repeated tracks. Sorry if I was unclear.

Found a possible method (have yet to try it), but perhaps there is a less circuitous one:

Duplicate track’s physical file with Finder via Applescript, then use the “add” command to get the new files into iTunes.

Got the code that grabs a track’s location and duplicates it working, but I can’t add the new file to iTunes without an error. I can do so if I prompt the user for the location and then select the new file and when I print the location it yields and the one returned by the Finder duplication they print as identical. Not sure why it won’t work.

            -- duplicate the track's file; I omitted the code that grabs the location and extracts the path as it works fine
	set DestinationPath to songPath
	set destinationFilename to "dupe " & filename
	with timeout of 20 seconds
		tell application "Finder"
				set theDupe to duplicate songLocation to folder DestinationPath
				--set name of theDupe to destinationFilename
			on error
				display dialog "Oops, a problem occurred duplicating the file."
			end try
		end tell
	end timeout

            -- seems to work fine up to this point, creating a duplicate in the same location as the original track's file
	tell application "iTunes"
		add theDupe to playlist "Test Playlist"      -- THIS DOES NOT WORK
	end tell

Tried casting theDupe to a few things but haven’t hit on the right commands. Any help would be appreciated. Also, how do I omit the need for a playlist and add directly to the main library? Tried a couple things but they failed. Thanks again.

change to

tell application "iTunes"
			add theDupe to playlist "Test Playlist"  
end try
		end tell

this is the way I did it

set DestinationPath to (choose file) as alias
tell application "Finder" to set filename to name of DestinationPath

set DestinationPath to POSIX path of DestinationPath
set AppleScript's text item delimiters to filename
set parentfolder to text item 1 of DestinationPath

set destinationFilename to parentfolder & "test_" & filename

set cmd to "cp '" & DestinationPath & "' '" & destinationFilename & "'"
do shell script cmd

delay 1
tell application "iTunes"
		add (POSIX file destinationFilename as alias) to playlist "Test1"
	end try
end tell

Putting the code in a try block suppresses the error but the file still isn’t added into iTunes. :frowning:

Tinkered with your copy method instead and managed to get it working with my location of track code. Thanks!

it’s quite simple: iTunes expects an alias specifier, so coerce the Finder object specifier to alias
The reference to the main library is library playlist 1 of source “Library”

tell application "iTunes"
	add (theDupe as alias) to library playlist 1 of source "Library"
end tell

Great! I was being too literal. When trying to figure it out I printed the class type of the path returned by a dialog to the user (the one that worked) and it spat out “alis” so I was trying to coerce it to that rather than “alias”. Is there some important reason for the one letter difference? My attempts to Google “alis” and “docf” (the returned object’s class from Finder’s duplicate operation) didn’t yield much info.

Thanks for your help.

alis and docf are string representations of enumerated constants as a four-letter code

For example the real value of alis is 1634494835, the formula in AppleScript is

(id of "a") * (2 ^ 24) + (id of "l") * (2 ^ 16) + (id of "i") * (2 ^ 8) + (id of "s")

In C/Objective-C you can easily wrap a four-letter string in single quotes (‘alis’) to get the integer value

Interesting. Is there a way to get the class of an object in a way that could be used as-is for casting?

it’s used for example

write something to fRef as «class utf8»

Thanks again to all who lent a hand. The script worked great. Took quite a while, but since it created 1,430 duplicate tracks in total that’s not too surprising. I added the new tracks to iTunes in batches to speed things up a bit.