Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Add Finder selection to iTunes library via AppleScript Apps
I just wrote an AppleScript that adds a selection (it can be files, folders, or both) to the iTunes library.

The script then deletes the original selected files (good if you have iTunes set to organize your files). This feature can be disabled in the script by marking the relevant line as a comment (--) in the source:
-- tell application "Finder" to delete selection_list
[robg adds: This works as described, though I would suggest commenting out the delete line, as shown above. If you don't, and you happen to try to add a file that the script doesn't support -- I first tested with a PDF -- then the source will be deleted without it being added to iTunes. (You could edit the script to add other file types, if you wish.) The deleted files can, however, be found in the trash.]
    •    
  • Currently 1.80 / 5
  You rated: 2 / 5 (5 votes cast)
 
[17,436 views]  

Add Finder selection to iTunes library via AppleScript | 2 comments | Create New Account
Click here to return to the 'Add Finder selection to iTunes library via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Add Finder selection to iTunes library via AppleScript
Authored by: loren_ryter on May 18, '06 08:16:04AM

There are already good scripts to do this. Try doing it with a contextual menu using bigcat, for example. scripts for that are part of WBC iTunes Scripts Collection.

Also, i concur with Rob, don't post scripts that deletes files the user isn't expecting to delete. It should be distributed without deleting.



[ Reply to This | # ]
Add Finder selection to iTunes library via AppleScript
Authored by: itsajeepthing111 on Nov 17, '07 07:08:26PM

Here is this script as a folder action. When new files are are added to the specified folder it checks if they are audio files, if they are it asks you if you want to add them to itunes. If you do, it will then ask if you want to delete the original files. Great for a folder that you download torrents to.

One thing I probably should add is a timeout feature (so if your not at your computer when the files are added the dialog box doesn't stay there), but it works fine without it.

property type_list : {"MPG3", "MIDI", "AIFF"}
property extension_list : {"mp3", "mid", "aif", "wav", "m4a"}

global numOfItems, all_items, source_folderName, audiofile_list, audioCheckReply, addReply

on adding folder items to source_folder after receiving these_items
--process items
set audiofile_list to {}
set all_items to these_items
set numOfItems to ((the count of these_items) as string)
set source_folderName to name of (info for source_folder)
repeat with i from 1 to (count of items) of these_items
set this_item to item i of these_items as alias
set the item_info to info for this_item
if folder of the item_info is true then
process_folder(this_item as alias)
else if (alias of the item_info is false) and ((the file type of the item_info is in the type_list) or the name extension of the item_info is in the extension_list) then
process_item(this_item as alias)
end if
end repeat
check()
end adding folder items to

on process_folder(this_folder)
set these_items to list folder this_folder without invisibles
repeat with x from 1 to the count of these_items
set this_itemPath to this_folder & (item x of these_items) as string
set this_item to this_itemPath as alias
set the item_info to info for alias this_itemPath
if folder of the item_info is true then
process_folder(this_item)
else if (alias of the item_info is false) and
((the file type of the item_info is in the type_list) or
the name extension of the item_info is in the extension_list) then
process_item(this_item as alias)
end if
end repeat
end process_folder

-- this sub-routine processes files
on process_item(this_item)
set the end of audiofile_list to (this_item as alias)
end process_item

on check()
if (count of audiofile_list) is greater than 0 then
with timeout of 4000 seconds
set audioCheckReply to display dialog "Do you want to add new audio files to iTunes?" buttons {"No", "Yes"} default button "No"
if button returned of audioCheckReply is "Yes" then
addFilesToITunes()
activate
if ((count of audiofile_list) is equal to 1) and ((count of numOfItems) is equal to 1) then
set addReply to display dialog "1 new item has been added to the iTunes library. Do you want to delete the 'original'?" buttons {"No", "Delete 'Original'"} default button "No"
else if (count of audiofile_list) is equal to 1 then
set addReply to display dialog "1 new item has been added to the iTunes library. Do you want to delete the 'original' or all of the new files that were added to '" & source_folderName & "'?" buttons {"No", "Delete 'Original'", "Delete All New Files"} default button "No"
else
set addReply to display dialog ((count of audiofile_list) as string) & " new items have been added to the iTunes library. Do you want to delete the 'originals' or all of the new files that were added to '" & source_folderName & "'?" buttons {"No", "Delete 'Originals'", "Delete All New Files"} default button "No"
end if
if (button returned of addReply is equal to "Delete 'Originals'") or (button returned of addReply is equal to "Delete 'Original'") then
tell application "Finder"
delete audiofile_list
end tell
else if (button returned of addReply is equal to "Delete All New Files") then
tell application "Finder" to delete all_items
end if
end if
end timeout
end if
end check

on addFilesToITunes()
tell application "iTunes"
launch
add audiofile_list to playlist "Library" of source "Library"
set lastItem to get end of audiofile_list
play lastItem
end tell
end addFilesToITunes



[ Reply to This | # ]