Help w/ Adding Files to iTunes
on adding folder items to this_folder after receiving these_items
tell application "Finder"
set this_name to the name of this_folder
end tell
repeat with i from 1 to count of items in these_items
set this_item to item i of these_items
dealWithFile(this_item)
-- Unsure, but do I need to delete this_item now?
end repeat
end adding folder items to
on dealWithFile(the_file)
set ext to getExtension(the_file)
if ext is "Text File" then
copyFile(the_file, getiPodPath() & "/Notes/")
else if ext is "iCal Calendar" then
copyFile(the_file, getiPodPath() & "/Calendars/")
else if ext is "AddressBook Card" then
copyFile(the_file, getiPodPath() & "/Contacts/")
else if ext is "iTunes Song" then
addToLibrary(the_file)
end if
end dealWithFile
on addToLibrary(this_file)
--This is where I don't know what to do!
--this_file is a file, and it is already known to be a QuickTime compatible format
end addToLibrary
on copyFile(the_file, the_dir)
do shell script "mv " & unix_path(POSIX path of the_file) & " " & the_dir
end copyFile
on getExtension(the_file)
set i to info for the_file
if name extension of i is "txt" then
return "Text File"
else if name extension of i is "" then
return "Text File"
else if name extension of i is "ics" then
return "iCal Calendar"
else if name extension of i is "vcf" then
return "AddressBook Card"
else if name extension of i is "mp3" then
return "iTunes Song"
else if name extension of i is "aif" then
return "iTunes Song"
else if name extension of i is "aiff" then
return "iTunes Song"
else if name extension of i is "mp4" then
return "iTunes Song"
else if name extension of i is "m4a" then
return "iTunes Song"
else if name extension of i is "m4p" then
return "iTunes Song"
else if name extension of i is "aac" then
return "iTunes Song"
else
return "File"
end if
end getExtension
on getiPod()
-- I'll prolly replace this with a loop that goes through the volumes looking for an ipod_control folder
tell application "iTunes"
repeat with i from 1 to the count of sources
if the kind of source i is iPod then
return source i
end if
end repeat
end tell
end getiPod
on getiPodPath()
set i to getiPod()
set s to name of i
set s to POSIX path of s
return unix_path(s)
end getiPodPath
-- Thanks to Dirk for adding this subroutine
-- This ripped from Rip to iPod
on unix_path(iPodPOSIX)
set chars to every character of iPodPOSIX
repeat with i from 1 to length of chars
if "!$&"�'*(){[|;<>?~` \" contains (item i of chars as text) then
set item i of chars to "\" & (item i of chars as text)
end if
end repeat
return every item of chars as string
end unix_path
Ok, I need some help with the addToLibrary subroutine.
Thanks!!!
TheMadRedHatter