Thursday, February 17, 2011

AppleScript and iTunes

Don't know about anyone else, but I've at times have had the need to either copy the contents of a play list or just the selected items displayed, to a folder external to itunes.  Could be a quick back-up for all items, let's say -  in Purchased, but maybe just need to copy the items to an external folder to be modified or edited.

Encountered a site http://dougscripts.com/itunes/ that has some great examples and tips on how to use AppleScript with iTunes.  I altered a script that moved items, to simply copy them.  Have to give the site credit, but thought it was a good enough sight to write a blog entry about! 

Check out Doug's site for more details how to write scripts and how to integrate them into iTunes.

Copy iTunes items ---

-- ************************************************
--
-- not to be used to redistribute copyrighted material!!!!
-- based on a script obtained from dougscripts.com/iTunes/
--
-- ************************************************
--
tell application "iTunes"
set trackList to the selection of window 1 -- any window with a selection
if ((count trackList) is 0) then
display dialog "No tracks are selected!" with icon caution buttons {"Drat"} default button 1
return
end if
set theFolder to choose folder with prompt "Pick folder to copy the selected tracks to"
if theFolder is not "" then
repeat with theTrack in trackList
set theTrackName to ((the location of theTrack)) -- may need to coerce to alias for OS 9
log theTrackName
tell application "Finder"
try
duplicate file theTrackName to theFolder
on error
tell application "iTunes"
display dialog "The Finder reported an error: The file [" & (theTrackName as string) & "] could not be copied to [" & theFolder & "]." with icon caution
end tell
end try
end tell
end repeat
display dialog "Finished!" buttons {"Thanks"} default button 1 with icon 1
end if
end tell

No comments:

Post a Comment