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.
TLDR:
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.
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"
try
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.
tell application "iTunes"
try
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"
try
add (POSIX file destinationFilename as alias) to playlist "Test1"
end try
end tell
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 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.