mingsai

Folder Action - Add Files to iTunes

Mar 1st, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. property type_list : {"MPG3", "MIDI", "AIFF"}
  2. property extension_list : {"mp3", "mid", "aif", "wav", "m4a"}
  3.  
  4. global numOfItems, all_items, source_folderName, audiofile_list, audioCheckReply, addReply
  5.  
  6. on adding folder items to source_folder after receiving these_items
  7. --process items
  8. set audiofile_list to {}
  9. set all_items to these_items
  10. set numOfItems to ((the count of these_items) as string)
  11. set source_folderName to name of (info for source_folder)
  12. repeat with i from 1 to (count of items) of these_items
  13. set this_item to item i of these_items as alias
  14. set the item_info to info for this_item
  15. if folder of the item_info is true then
  16. process_folder(this_item as alias)
  17. 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
  18. process_item(this_item as alias)
  19. end if
  20. end repeat
  21. check()
  22. end adding folder items to
  23.  
  24. on process_folder(this_folder)
  25. set these_items to list folder this_folder without invisibles
  26. repeat with x from 1 to the count of these_items
  27. set this_itemPath to this_folder & (item x of these_items) as string
  28. set this_item to this_itemPath as alias
  29. set the item_info to info for alias this_itemPath
  30. if folder of the item_info is true then
  31. process_folder(this_item)
  32. else if (alias of the item_info is false) and ¬
  33. ((the file type of the item_info is in the type_list) or ¬
  34. the name extension of the item_info is in the extension_list) then
  35. process_item(this_item as alias)
  36. end if
  37. end repeat
  38. end process_folder
  39.  
  40. -- this sub-routine processes files
  41. on process_item(this_item)
  42. set the end of audiofile_list to (this_item as alias)
  43. end process_item
  44.  
  45. on check()
  46. if (count of audiofile_list) is greater than 0 then
  47. with timeout of 4000 seconds
  48. set audioCheckReply to display dialog "Do you want to add new audio files to iTunes?" buttons {"No", "Yes"} default button "No"
  49. if button returned of audioCheckReply is "Yes" then
  50. addFilesToITunes()
  51. activate
  52. if ((count of audiofile_list) is equal to 1) and ((count of numOfItems) is equal to 1) then
  53. 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"
  54. else if (count of audiofile_list) is equal to 1 then
  55. 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"
  56. else
  57. 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"
  58. end if
  59. if (button returned of addReply is equal to "Delete 'Originals'") or (button returned of addReply is equal to "Delete 'Original'") then
  60. tell application "Finder"
  61. delete audiofile_list
  62. end tell
  63. else if (button returned of addReply is equal to "Delete All New Files") then
  64. tell application "Finder" to delete all_items
  65. end if
  66. end if
  67. end timeout
  68. end if
  69. end check
  70.  
  71. on addFilesToITunes()
  72. tell application "iTunes"
  73. launch
  74. add audiofile_list to playlist "Library" of source "Library"
  75. set lastItem to get end of audiofile_list
  76. play lastItem
  77. end tell
  78. end addFilesToITunes
Advertisement
Add Comment
Please, Sign In to add comment