Hi there,
I've got a small question. I'm currently using the code below to make playlists in Itunes from my music collection. Currently it's naming the playlists as follows:
Would be great if anyone could do a suggestion to change to code below so the folder (and playlist) would be just be called 'disco', instead of what it's right now (see the image for an example).
As you might have read, I'm a noob at this stuff. Would be great if you could share your wisdom to make this world a better place
. Thanks!
I've got a small question. I'm currently using the code below to make playlists in Itunes from my music collection. Currently it's naming the playlists as follows:
Would be great if anyone could do a suggestion to change to code below so the folder (and playlist) would be just be called 'disco', instead of what it's right now (see the image for an example).

As you might have read, I'm a noob at this stuff. Would be great if you could share your wisdom to make this world a better place
Code:
property pathsList : {}
global addedFiles
set addedFiles to 0
global root_folder
tell application "Finder"
set root_folder to choose folder with prompt "Please select directory."
set root_name to name of root_folder
tell application "iTunes"
set root_path to POSIX path of root_folder
set root_ID to persistent ID of (make folder playlist with properties {name:root_path})
set holder_ID to my createPlaylistHolder("/", root_ID)
end tell
my recurseDir(root_folder, root_ID, holder_ID, false)
end tell
if addedFiles is greater than 0 then
activate
display dialog "Added " & addedFiles & " songs ." buttons {"OK"}
end if
if addedFiles is 0 then
activate
display dialog "Did add any songs ." buttons {"OK"}
end if
return pathsList
on recurseDir(parent_folder, parent_ID, holder_ID, stopFolding)
set item_list to ""
tell application "System Events"
set item_list to get the name of every disk item of parent_folder
end tell
set item_count to (get count of items in item_list)
repeat with i from 1 to item_count
set the_item to item i of the item_list
set the_item to ((parent_folder & the_item) as string) as alias
set item_path to POSIX path of the_item
tell application "System Events"
set file_info to get info for the_item
end tell
if visible of file_info is true then
if folder of file_info is true then
set end of pathsList to item_path & "
"
set new_playlist_name to name of root_path
if "@" is in new_playlist_name or "#" is in new_playlist_name or "$" is in new_playlist_name or parent_folder is root_folder then
set new_parent_ID to my createPlaylistFolder(new_playlist_name, parent_ID)
set new_holder_ID to my createPlaylistHolder("/", new_parent_ID)
my recurseDir(the_item, new_parent_ID, new_holder_ID, false)
else
set new_parent_ID to parent_ID
if stopFolding is true then
set new_holder_ID to holder_ID
my recurseDir(the_item, new_parent_ID, new_holder_ID, true)
else
set new_holder_ID to my createPlaylistHolder(new_playlist_name, parent_ID)
my recurseDir(the_item, new_parent_ID, new_holder_ID, true)
end if
end if
else
addSongToPlaylist(the_item, holder_ID)
end if
end if
end repeat
end recurseDir
on createPlaylistFolder(new_playlist_name, parentID)
tell application "iTunes"
try
set new_id to persistent ID of (make folder playlist at (some folder playlist whose persistent ID is parentID) with properties {name:new_playlist_name})
end try
end tell
return new_id
end createPlaylistFolder
on createPlaylistHolder(new_playlist_name, parentID)
tell application "iTunes"
try
set theid to persistent ID of (make playlist at (some folder playlist whose persistent ID is parentID) with properties {name:new_playlist_name})
end try
end tell
return theid
end createPlaylistHolder
on addSongToPlaylist(theFile, playlistID)
tell application "iTunes"
try
set thePlaylist to (some user playlist whose persistent ID is playlistID)
add theFile to thePlaylist
set addedFiles to addedFiles + 1
my progressNotice()
end try
end tell
end addSongToPlaylist
on progressNotice()
if frontmost then
if (addedFiles mod 1000) is 0 then
display dialog "Added " & addedFiles & " songs so far ." buttons {"OK"} giving up after 10
end if
end if
end progressNotice