Advertisement
Guest User

Untitled

a guest
Jun 10th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. tell application "iTunes"
  2.     -- globals
  3.     set thePlaylist to "jtunes"
  4.     set theMaxSizeInMegabytes to 500
  5.    
  6.     -- get the list of albums
  7.     set allAlbumsList to {}
  8.     set albumList to album of file tracks of library playlist "Library" whose kind contains "audio"
  9.     set tcount to count albumList
  10.     repeat with i from 1 to tcount
  11.         tell my albumList's item i to if it is not in my allAlbumsList and it is not "" then set end of my allAlbumsList to it
  12.     end repeat
  13.    
  14.     -- create and or delete the playlist
  15.     if exists (some user playlist whose name is thePlaylist) then delete (some user playlist whose name is thePlaylist)
  16.     set myPlaylist to make new playlist with properties {name:thePlaylist}
  17.    
  18.     -- fill the playlist
  19.     set selectedAlbums to {}
  20.     set selectedSize to 0
  21.     set done to false
  22.     repeat until done
  23.         tell (some item of allAlbumsList) to if (it is not in selectedAlbums) then set end of selectedAlbums to it
  24.         set theAlbum to end of selectedAlbums
  25.         set albumSize to 0
  26.         set albumTracks to (every file track of library playlist "Library" whose album is theAlbum)
  27.         repeat with aTrack in albumTracks
  28.             set albumSize to albumSize + (size of aTrack)
  29.         end repeat
  30.         set albumSize to albumSize / 1024 / 1024
  31.        
  32.         if albumSize + selectedSize > theMaxSizeInMegabytes then
  33.             display dialog "have a great day"
  34.             set done to true
  35.         else
  36.             set selectedSize to selectedSize + albumSize
  37.             set albumTracks to (every file track of library playlist "Library" whose album is theAlbum)
  38.             repeat with aTrack in albumTracks
  39.                 duplicate aTrack to myPlaylist
  40.             end repeat
  41.         end if
  42.     end repeat 
  43. end tell
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement