Skip to content

Instantly share code, notes, and snippets.

@DJJonnyFeeke
Created November 21, 2017 12:31
Show Gist options
  • Save DJJonnyFeeke/303a057c94f1e152ffa245a321d7ae5d to your computer and use it in GitHub Desktop.
Save DJJonnyFeeke/303a057c94f1e152ffa245a321d7ae5d to your computer and use it in GitHub Desktop.
iTunes Playlist Manager
(*
"DJ Jonny F's iTunes Repair" for iTunes
written by Jonathan Feeke
[email protected]
*)
--===========LIST OF DEFAULT VARIABLES===========--
property my_title : "DJ Jonny F's iTunes Repair"
property myFileName : ""
property newName : ""
--===========LIST OF TAGS TO MODIFY===========--
--These are the tags that will be selected by default.
property my_tags_to_modify : {"name", "artist"}
--===========LIST OF LOWERCASE WORDS===========--
--These are the words that will remain lowercase, unless they begin or end the title.
property lowercase_words : {"a", "an", "and", "at", "but", "by", "for", "in", "nor", "of", "on", "or", "so", "to", "with", "amid", "anti", "as", "down", "into", "like", "near", "off", "onto", "out", "over", "past", "per", "plus", "save", "some", "than", "till", "up", "upon", "via", "yet", "the"}
--===========LIST OF UNMODIFIED WORDS===========--
--These are the words that won't be modified at all. It's a good place to put all-uppercase words.
property unmodified_words : {"FM", "USA", "WDPK", "OYF’N", "UR", "TV", "MGM", "DVD", "ABC", "CD", "USSR", "CA", "WA", "NY", "NYC", "LP", "EP", "VHS", "UK", "GB", "'Bout", "'Cause", "o'", "'n'", "n'", "McCartney", "vs.", "de", "feat.", "Pi-hsien", "von", "van"}
--===========LIST OF TRAILING CHARACTERS===========--
--Any word trailed by a character in this list will be title cased. (ie. "a song" (with a remix) -> "A Song" (With a Remix))
property other_chars : "_!\"$%&/()=¿?@¡|#¢∞“”[]{}*-+•«»—´`ºª…:;."
property lowercase_match : false
property unmodified_Match : false
property other_chars_match : false
property my_tags : my_tags_to_modify
global editableText, replacementText
-- you may want to experiment with these properties to refine your searches!
property limit_to_size : false --if set to true, will only serch for images described in image_size
property image_size : "medium" --can be 'icon' 'small' 'medium' 'large'
property limit_to_domain : false --if set to true, will search only in the domain described in search_domain
property search_domain : "amazon.com" --search for images only in a certian domain/website, such as 'amazon.com' or 'artistdirect.com'
--======================--
-- you probably don't want to change anything below here
property search_URL : "http://images.google.com/images?ie=ISO-8859-1&hl=en&btnG=Google+Search&q="
--properties for the add files to itunes
--property pathsList : {}
global addedFiles
set addedFiles to 0
global addedFolders
set addedFolders to 0
global root_folder
--global deleted_count
--======================--
tell application "System Events"
set theUser to (get full name of current user)
end tell
tell application "iTunes"
--##################################NEW WAY OF SELECTING LARGE AMOUNTS OF TRACKS##################################
--set fx to fixed indexing
--set fixed indexing to true
--set thisPlaylist to (a reference to (get view of front window))
--if selection is not {} then --test if there is a selection
-- set using_selection to true
-- set idx to (count selection's items)
--else --it's the whole playlist
-- set selectedTracks to (get a reference to thisPlaylist)
-- set using_selection to false
-- set idx to (count thisPlaylist's tracks)
--end if
--##################################NEW WAY OF SELECTING LARGE AMOUNTS OF TRACKS##################################
--##################################How to Seperate Code into other Scripts##################################
--set myScript to load script file ((path to scripts folder as text) & "testScript.scpt")
--tell myScript
-- set it's localVariable to "This Value"
-- subRoutine1() --subroutine in the loaded script, in case you dont want the whole script to run
--end tell
--End Seperate Code into other scripts
set sel to selection
--############################################################################
set mySettings to button returned of (display dialog theUser & ", This Tool is Divided into 4 Parts, each having Three Choices, if you do not need to use a function, just select it then cancel it to move on." & return & return & "Thanks for using this Script from Jonathan Feeke ([email protected])" & return buttons {"Settings", "Ok"} default button 1 with icon 1 with title my_title giving up after 60)
if mySettings = "Settings" then
tell application "Finder"
if exists (POSIX file "/Library/Itunes/Scripts/DJJonny's iTunes Repair Settings.txt") then
open file (POSIX file "/Library/Itunes/Scripts/DJJonny's iTunes Repair Settings.txt")
else
tell application "TextEdit"
--activate
make new document
set text of document 1 to ("Audio") & {return} & {"mp3,wav,m4a" as text} & {return} & ("Movies") & {return} & {"avi,mpg,mkv,flv" as text} & {return} & ("Mac Software") & {return} & {"dmg,pkg,zip,rar,7z,iso" as text} & {return} & ("Win Software") & {return} & {"msi,exe,zip,7z,iso" as text} & {return} & ("Images") & {return} & {"jpg,jpeg,bmp,png,gif,tiff" as text} & {return} & ("Music Videos") & {return} & {"avi,mkv,flv,mp4,mpe,asf,mpeg" as text}
save document 1 in (POSIX file "/Library/iTunes/Scripts/DJJonny's iTunes Repair Settings.txt")
close document 1 without saving
open file (POSIX file "/Library/Itunes/Scripts/DJJonny's iTunes Repair Settings.txt")
end tell
end if
display dialog theUser & ", Please do not change the Format of this Document, but you can add other formats" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
end tell
return
end if
if mySettings = "Ok" then
tell application "Finder"
if exists (POSIX file "/Library/Itunes/Scripts/DJJonny's iTunes Repair Settings.txt") then
--we are trying to see if the user has a settings file, which is required by this tool to function
else
display dialog theUser & ", Please First Initialize the Settings, which is once off. Settings can be Changed and more Formats added as well." & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
end if
end tell
end if
--##########################################
set myCreation to button returned of (display dialog "Choose which process you would like to run: (Part 1)" & return buttons {"Create New Structure", "Import Tracks", "Renamer"} default button 1 with title my_title with icon caution)
--##########################################
if myCreation = "Create New Structure" then
set myCreateDJStructure to button returned of (display dialog "Would you like to Create a NEW Structure?" & return & "N.B: Creates Playlist Folders and Playlists Automatically for use with this Tool" & return buttons {"Yes", "No"} default button 2 with title my_title with icon 1)
if myCreateDJStructure = "Yes" then
set inputText to text returned of (display dialog "Main Structure Name OR DJ Name:" default answer "")
if (inputText = "" or inputText = false) then
display dialog theUser & ", You need to use a Main Structure Name, this Process will Exit" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
else
with timeout of 30000 seconds
-- make new Playlist; if it already exists, tell the user to use a new name and exit
set fPLists to (get every folder playlist)
set fExist to ""
repeat with fPList in fPLists
ignoring case
if (name of fPList = inputText) then
set fExist to 1
end if
end ignoring
end repeat
if not (fExist = 1) then
set mainPlaylist to make new folder playlist with properties {name:inputText}
set view of front browser window to folder playlist inputText
--this next step sets all the playlist folders you will need for your database, you can remove ,add or edit names as needed N.B. Lists should not be empty
set folList to {"Comedy", "Compilations", "Country", "Cultural", "Dance", "DJ Compilations", "DubStep", "Gospel", "Hip Hop", "House", "iTunes", "Jazz", "Latino", "Local", "Megamix", "Music Videos", "Pop", "Radio Casts", "Rap", "Reggae", "RnB", "Slow", "Sound Effects"} as list
set plList to {"60's", "70's", "80's", "90's", "Chilled", "Lounge", "Party", "Underground", "Upbeat", "Acapella", "Funky", "Retro", "Radio", "Acid Funk", "Black", "Deep", "Disco", "Electro", "Garage", "Gospel", "Intro", "Jackin", "Progressive", "Soulfull", "Techno", "Trance"} as list
set theFolders to {} as list
--loop until the user choose the playlist folders
set folLoop to true
repeat while folLoop is true
set chooseFol to (choose from list folList with title my_title with prompt "Choose Playlist Folders: (multi-select)" & return & "(Add allows you to Create your Own Names)" & return OK button name "Next" cancel button name "Add" with multiple selections allowed)
if (chooseFol = false) then
set inputFol to text returned of (display dialog "Create a Playlist Folder Name:" default answer "")
if (inputFol = "" or inputFol = false) then
display dialog theUser & ", You need to use Playlist Folder Names, this Process will Exit" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
else
set folList to folList & inputFol
set folLoop to true
end if
else
set folLoop to false
set theFolders to (chooseFol as list)
end if
end repeat
--loop the playlist folders and ask for additional playlist names then create them
set theFol to "" as text
repeat with theFol in theFolders
set plLoop to true
repeat while plLoop is true
set choosePl to (choose from list plList with title my_title with prompt "Choose Playlist Names for Current PlayList Folder: (multi-select)" & return & "(PlayList Folder:" & theFol & ")" & return OK button name "Next" cancel button name "Add" with multiple selections allowed)
if (choosePl = false) then
set inputPl to text returned of (display dialog "Create a Playlist Name for Playlist Folder:(" & theFol & ")" default answer "")
if (inputPl = "" or inputPl = false) then
display dialog theUser & ", You need to use Playlist Names, this Process will Exit" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
else
set plList to plList & inputPl
set plLoop to true
end if
else
set plLoop to false
--create the playlist folder and playlists per tier
set newPlaylistFolder to make new folder playlist at mainPlaylist with properties {name:theFol}
set thePlaylists to (choosePl as list)
repeat with thePList in thePlaylists
make new user playlist at newPlaylistFolder with properties {name:thePList}
end repeat
end if
end repeat
end repeat
display dialog theUser & ", Main Structure Creation is Complete!" & return & "Thanks for using this Script from Jonathan Feeke ([email protected])" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
else
display dialog theUser & ", Main Structure Name OR DJ Name already exists, this Process will Exit, please use a NEW Name that does not exist in your Library" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
end if
end timeout
end if
end if
return
else if myCreation = "Import Tracks" then
--##########################################
set addNewFiles to button returned of (display dialog "Would you like to Add New Files to iTunes?" & return & "N.B: Creates Folders & Playlists Automatically and structures just like your folder structure" & return buttons {"Yes", "No"} default button 2 with title my_title with icon 1)
if addNewFiles = "Yes" then
set addedFiles to 0
set addedFolders to 0
with timeout of 1000000 seconds
tell application "Finder"
set root_folder to choose folder with prompt "Please select a directory to Import:"
set root_name to displayed name of root_folder
--use the settings file to get the types
--##############################
set mySettingsFile to paragraphs of (read POSIX file "/Library/Itunes/Scripts/DJJonny's iTunes Repair Settings.txt")
set AppleScript's text item delimiters to {","}
set myInt to 1
repeat with nextLine in mySettingsFile
set nextLine to text items of nextLine
if myInt = 2 then
set fileTypes to (nextLine as list)
end if
set myInt to (myInt + 1)
end repeat
set AppleScript's text item delimiters to {""}
--##############################
--end the settings file to get the types
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 view of front browser window to folder playlist root_path
end tell
my recurseDir(root_folder, root_ID, fileTypes)
end tell
end timeout
if addedFiles is greater than 0 then
activate
display dialog theUser & "," & addedFiles & " Tracks were Added Successfully from " & addedFolders & " Folders! This Process is Complete!" & return & "Thanks for using this Script from Jonathan Feeke ([email protected])" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
end if
if addedFiles is 0 then
activate
display dialog "Could not Find any Tracks." buttons {"Ok"} with title my_title with icon caution
end if
set addedFiles to 0
set addedFolders to 0
end if
else
--##########################################
set myFolderReNamer to button returned of (display dialog "Would you like to Re-Name Folders/Movie Files/Music Videos?" & return & "N.B: Folders/Movie/Music Video Files will be Re-Named into two/three parts e.g. Part1 (Part2) for Folders and Movies, and Part1 - Part2 (Part3) for Music Videos" & return & "(Brackets are added automatically)" & return buttons {"Yes", "No"} default button 2 with title my_title with icon 1)
if myFolderReNamer = "Yes" then
tell application "Finder"
set root_folder to choose folder with prompt "Please select a directory to Analyze (1 Level Deep):"
set root_name to displayed name of root_folder
set folList to ""
set chooseType to (choose from list {"Folder", "Movie", "Music Video"} with title my_title with prompt "Choose a Type to Re-Name: " & return OK button name "Next" cancel button name "Cancel")
if chooseType = false then
display dialog theUser & ", the Process has been Cancelled!" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
else
try
set folList to {} as list
if ((chooseType as string) = "Movie") then
--use the settings file to get the types
--##############################
set mySettingsFile to paragraphs of (read POSIX file "/Library/Itunes/Scripts/DJJonny's iTunes Repair Settings.txt")
set AppleScript's text item delimiters to {","}
set myInt to 1
repeat with nextLine in mySettingsFile
set nextLine to text items of nextLine
if myInt = 4 then
set fileTypes to (nextLine as list)
end if
set myInt to (myInt + 1)
end repeat
set AppleScript's text item delimiters to {""}
--##############################
--end the settings file to get the types
set folList to get every item of root_folder whose name extension is in fileTypes --{"avi", "mpg", "mkv", "flv"} --kind is "AVI Container" or kind is "Flash Video File" or kind is "MPEG-4 File" or kind is "Matroska Video File"
end if
if ((chooseType as string) = "Folder") then
set folList to get every item of root_folder whose kind is (chooseType as string)
end if
if ((chooseType as string) = "Music Video") then
--use the settings file to get the types
--##############################
set mySettingsFile to paragraphs of (read POSIX file "/Library/Itunes/Scripts/DJJonny's iTunes Repair Settings.txt")
set AppleScript's text item delimiters to {","}
set myInt to 1
repeat with nextLine in mySettingsFile
set nextLine to text items of nextLine
if myInt = 12 then
set fileTypes to (nextLine as list)
end if
set myInt to (myInt + 1)
end repeat
set AppleScript's text item delimiters to {""}
--##############################
--end the settings file to get the types
set folList to get every item of root_folder whose name extension is in fileTypes --{"avi", "mpg", "mkv", "flv"} --kind is "AVI Container" or kind is "Flash Video File" or kind is "MPEG-4 File" or kind is "Matroska Video File"
end if
--set the_pList to the displayed name of (info for root_folder)
on error --no files
set folList to {}
display dialog theUser & ", Could not Locate any Items for Processing!" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
end try
try
--set folcount to (get count of items in folList)
set fList to {} as list
repeat with folName in folList
set fList to fList & (get name of folName)
end repeat
set folNames to (choose from list fList with title my_title with prompt "Choose the " & (chooseType as string) & "s to Re-Name: (multi-select)" & return & "(only edit the one's you really want to)" & return OK button name "Next" cancel button name "Cancel" with multiple selections allowed)
if folNames = false then
display dialog theUser & ", the Process has been Cancelled!" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
else
repeat with folItem in folNames
--find and replace characters not needed
ignoring case
set AppleScript's text item delimiters to space
set folItemSplit to my findAndReplace("_", " ", folItem)
set folItemSplit to my findAndReplace("-", " ", folItemSplit)
set folItemSplit to my findAndReplace(".", " ", folItemSplit)
set AppleScript's text item delimiters to {""}
end ignoring
--MODIFY CAPITILIZATION
set theTitle_as_List to (my text_to_list(folItemSplit, space))
set newTitle to {}
set last_item to (count theTitle_as_List)
set word_counter to 1
repeat with editableText in theTitle_as_List
set replacementText to ""
repeat with my_unmodified_Match in unmodified_words
--Check if any of the words belong to the list of unmodified words.
if (my_unmodified_Match as text) = (editableText as text) then
set unmodified_Match to true
exit repeat
end if
end repeat
if unmodified_Match then
--Unmodify matching words in unmodified_words list (actually just copy the word from the list).
set replacementText to my_unmodified_Match as text
set unmodified_Match to false
else if (word_counter = 1) or (word_counter = last_item) then
--Capitalize first and last words in title.
my SetCase(editableText)
else
--For words not beginning or ending the title (middle words).
repeat with my_lowercase_Match in lowercase_words
--Check if any of the middle words belong to the list of lowerase words.
if (my_lowercase_Match as text) = (editableText as text) then
set lowercase_match to true
exit repeat
end if
end repeat
if lowercase_match then
--Lowercase matching words in lowercase_words list (actually just copy the word from the list).
set replacementText to my_lowercase_Match as text
set lowercase_match to false
else
--Capitalize the rest of the words.
my SetCase(editableText)
end if
end if
copy replacementText to end of newTitle
set word_counter to (word_counter + 1)
end repeat
-->> log (my list_to_text(newTitle, space)) -- de-bugging only
try
set folItemSplit to my list_to_text(newTitle, space)
end try
--END MODIFY CAPITILIZATION
set folWords to words of folItemSplit as list
if ((chooseType as string) = "Music Video") then
set part1 to (choose from list folWords with title my_title with prompt ("Choose the " & (chooseType as string) & " Name/Artist: (multi-select)" & return & "Current Title:" & return & folItem as string) & return & "(the order is as the list is)" & return OK button name "Next" cancel button name "Cancel" with multiple selections allowed)
set part2 to (choose from list folWords with title my_title with prompt ("Choose the " & (chooseType as string) & "Track Name: (multi-select)" & return & "Current Title:" & return & folItem as string) & return & "(the order is as the list is)" & return OK button name "Next" cancel button name "Cancel" with multiple selections allowed)
set part3 to (choose from list folWords with title my_title with prompt ("Choose the " & (chooseType as string) & " Bracketed Name: (multi-select)" & return & "Current Title:" & return & folItem as string) & return & "(this can be cancelled if not required)" & return OK button name "Next" cancel button name "Cancel" with multiple selections allowed)
else
set part1 to (choose from list folWords with title my_title with prompt ("Choose the " & (chooseType as string) & " Name: (multi-select)" & return & "Current Name:" & return & folItem as string) & return & "(the order is as the list is)" & return OK button name "Next" cancel button name "Cancel" with multiple selections allowed)
set part2 to (choose from list folWords with title my_title with prompt ("Choose the " & (chooseType as string) & " Bracketed Name: (multi-select)" & return & "Current Name:" & return & folItem as string) & return & "(this can be cancelled if not required)" & return OK button name "Next" cancel button name "Cancel" with multiple selections allowed)
end if
--edit and re-name the file/folder
set renameThis to get (every item of root_folder whose name is folItem)
set AppleScript's text item delimiters to space
if part1 = false then
display dialog theUser & ", you have cancelled your current Re-Naming, the Process will move to the next..." & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
else
if ((chooseType as string) = "Music Video") then
if part1 = false then
display dialog theUser & ", you have cancelled your current Re-Naming, the Process will move to the next..." & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
else
if part2 = false then
if part3 = false then
set name of (item 1 of renameThis) to (part1 as string) & "." & name extension of (item 1 of renameThis)
else
set name of (item 1 of renameThis) to ((part1 as string) & " (" & (part3 as string) & ")") & "." & name extension of (item 1 of renameThis)
end if
else
if part3 = false then
set name of (item 1 of renameThis) to ((part1 as string) & " - " & (part2 as string)) & "." & name extension of (item 1 of renameThis)
else
set name of (item 1 of renameThis) to ((part1 as string) & " - " & (part2 as string) & " (" & (part3 as string) & ")") & "." & name extension of (item 1 of renameThis)
end if
end if
end if
else
if part2 = false then
if ((chooseType as string) = "Movie") then
set name of (item 1 of renameThis) to (part1 as string) & "." & name extension of (item 1 of renameThis)
else
set name of (item 1 of renameThis) to (part1 as string)
end if
else
if part1 = false then
display dialog theUser & ", you have cancelled your current Re-Naming, the Process will move to the next..." & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
else
if ((chooseType as string) = "Movie") then
set name of (item 1 of renameThis) to ((part1 as string) & " (" & (part2 as string) & ")") & "." & name extension of (item 1 of renameThis)
else
set name of (item 1 of renameThis) to ((part1 as string) & " (" & (part2 as string) & ")")
end if
end if
end if
end if
end if
set AppleScript's text item delimiters to {""}
end repeat
end if
end try
end if
end tell
display dialog theUser & ", Re-Name is Complete!" & return & "Thanks for using this Script from Jonathan Feeke ([email protected])" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
end if
--##########################################
set myChoice to button returned of (display dialog "Choose which process you would like to run: (Part 2)" & return & return buttons {"Sort and Move", "Listen and Edit", "Search and Download"} default button 1 with title my_title with icon caution)
--##########################################
if myChoice = "Search and Download" then
--##########################################
set opt to button returned of (display dialog "Would you like to Search and Download?" & return & "Searches YouTube for a Track you Specify" & return & "Asks for Confirmation (Update if Required)" & return & "Downloads Track as mp3" & return buttons {"Yes", "No"} default button 2 with title my_title with icon 1)
if opt = "Yes" then
end if
end if
if myChoice = "Sort and Move" then
--##########################################
set opt to button returned of (display dialog "Would you like to Sort and Move Files?" & return & "N.B: Folders & Movies & Software & Audio & Image - Files will be Sorted and Moved into a Proper Structure as Shown Below:" & return & "Legend: [] = Folder, () = Files" & return & return & "-[Folder] -> [Image],[Audio],[Movie],[Software] -> [Various] ->[Move]" & return & "-[Images] -> [Ext] -> [Size] -> (Move)" & return & "-[Audio] --> [Ext] -> (Move)" & return & "-[Software] -> [Apple Mac],[Microsoft Windows] -> [Ext] -> (Move)" & return & "-[Movie] -> [A],[B],[C] etc -> [Ext] -> (Move with First Letter of File to [A],[B],[C] etc)" & return & "-[Image],[Audio],[Movie] --> [Ext] ->(Move)" & return & "-[Music Video] -> [Ext] -> (Move)" & return buttons {"Yes", "No"} default button 2 with title my_title with icon 1)
if opt = "Yes" then
tell application "Finder"
set root_folder to choose folder with prompt "Please select a directory to Analyze (1 Level Deep):"
set root_name to displayed name of root_folder
set root_path to POSIX path of root_folder
set filList to ""
--Manage Folders by asking the user to select the kind of files within or MOVE to a DIRTY Folder
set chooseType to (choose from list {"Folder", "Software", "Audio", "Movie", "Image", "Music Video", "ALL (Audio,Movie,Image)"} with title my_title with prompt "Choose a Type to Analyze: " & return OK button name "Next" cancel button name "Cancel")
if chooseType = false then
display dialog theUser & ", the Process has been Cancelled!" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
else
try
--use the settings file to get the types
--##############################
set mySettingsFile to paragraphs of (read POSIX file "/Library/Itunes/Scripts/DJJonny's iTunes Repair Settings.txt")
--open for access mySettingsFile
--set settingsContents to read mySettingsFile using delimiter {return}
--close access mySettingsFile
set AppleScript's text item delimiters to {","}
set myInt to 1
repeat with nextLine in mySettingsFile
set nextLine to text items of nextLine
if myInt = 2 then
set fileTypesAud to (nextLine as list)
set fileTypesALL to (nextLine)
end if
if myInt = 4 then
set fileTypesMov to (nextLine as list)
set fileTypesALL to (fileTypesALL & nextLine)
end if
if myInt = 6 then
set fileTypesMacSof to (nextLine as list)
end if
if myInt = 8 then
set fileTypesWinSof to (nextLine as list)
end if
if myInt = 10 then
set fileTypesImg to (nextLine as list)
set fileTypesALL to (fileTypesALL & nextLine)
end if
if myInt = 12 then
set fileTypesMVid to (nextLine as list)
set fileTypesALL to (fileTypesALL & nextLine)
set fileTypesALL to text items of fileTypesALL
set fileTypesALL to (fileTypesALL as list)
end if
set myInt to (myInt + 1)
end repeat
set AppleScript's text item delimiters to {""}
--set fileTypesALL to (item 2 & ", " & item 4 & ", " & item 10) as list
--##############################
--end the settings file to get the types
set filList to {} as list
if ((chooseType as string) = "Folder") then
set filList to get the name of every item of root_folder whose kind is "folder"
end if
if ((chooseType as string) = "Movie") then
set filList to get the name of every item of root_folder whose name extension is in fileTypesMov --{"avi", "mpg", "mkv", "flv"} --kind is "AVI Container" or kind is "Flash Video File" or kind is "MPEG-4 File" or kind is "Matroska Video File"
end if
if ((chooseType as string) = "Software") then
set chooseTypeSof to (choose from list {"Apple Mac", "Microsoft Windows"} with title my_title with prompt "Choose a Operating System: " & return OK button name "Next" cancel button name "Cancel")
if chooseTypeSof = false then
display dialog theUser & ", the Process has been Cancelled!" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
else
if (chooseTypeSof as string) = "Apple Mac" then
set filList to get the name of every item of root_folder whose name extension is in fileTypesMacSof --{"dmg", "pkg", "zip", "rar", "7z", "iso"}
else
set chooseTypeSof to "Microsoft Windows" as string
set filList to get the name of every item of root_folder whose name extension is in fileTypesWinSof --{"msi", "exe", "zip", "rar", "7z", "iso"}
end if
end if
end if
if ((chooseType as string) = "Audio") then
set filList to get the name of every item of root_folder whose name extension is in fileTypesAud --{"mp3", "wav", "m4a"}
end if
if ((chooseType as string) = "Image") then
set filList to get the name of every item of root_folder whose name extension is in fileTypesImg --{"jpg", "jpeg", "bmp", "png", "tiff", "gif"}
end if
if ((chooseType as string) = "ALL (Audio,Movie,Image)") then
set filList to get the name of every item of root_folder whose name extension is in fileTypesALL --all the extensions to a VARIOUS folder
end if
if ((chooseType as string) = "Music Video") then
set filList to get the name of every item of root_folder whose name extension is in fileTypesMVid --all the extensions to a VARIOUS folder
end if
--set the_pList to the displayed name of (info for root_folder)
on error --no files
set filList to {}
display dialog theUser & ", Could not Locate any Information for Processing!" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
end try
try
--set folcount to (get count of items in folList)
set fList to {} as list
repeat with filName in filList
set fList to fList & (filName)
end repeat
set typeList to {"Audio", "Movie", "Image", "Software"} as list
if ((chooseType as string) = "Folder") then
repeat with theType in typeList
set filNames to (choose from list fList with title my_title with prompt "Choose " & (theType as string) & " Folders to Sort and Move: (multi-select)" & return & "(only select the one's that apply)" & return OK button name "Next" cancel button name "Skip" with multiple selections allowed)
if filNames = false then
--display dialog theUser & ", the Process has been Cancelled!" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
--return
else
--remove selected items from list
try
set itemsToRemove to filNames
set cleanList to {}
repeat with i from 1 to (count fList)
if (fList's item i) is not in itemsToRemove then set cleanList's end to fList's item i
end repeat
set fList to cleanList
on error error_message number error_number
display dialog error_message & error_number buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end try
--end remove
set myCheck to button returned of (display dialog "Confirm you want to:" & return & "Move " & (chooseType as string) & " (s) to a New OR Existing " & (theType as string) & " Folder?" & return & return & "N.B. Folders are created within the Analyze Folder Chosen" & return buttons {"Yes", "No"} default button 2 with title my_title with icon caution)
if myCheck = "Yes" then
--work gets done here for folders
if (exists folder theType of root_folder) is true then
if (exists folder "Various" of (((root_folder as text) & (theType as text)) as alias)) is true then
repeat with theFile in filNames
set aFile to (get every item of root_folder whose name is (theFile as string) and kind is "Folder")
try
move aFile to folder ((root_folder as text) & (theType as text) & ":" & "Various")
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for Folder:" & (theFile as string) & return & return & "N.B. All Contents will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (theType as text) & ":" & "Various") with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for Folder:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
end repeat
else
make new folder at (((root_folder as text) & (theType as text)) as alias) with properties {name:"Various"}
repeat with theFile in filNames
set aFile to (get every item of root_folder whose name is (theFile as string) and kind is "Folder")
try
move aFile to folder ((root_folder as text) & (theType as text) & ":" & "Various")
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for Folder:" & (theFile as string) & return & return & "N.B. All Contents will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (theType as text) & ":" & "Various") with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for Folder:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
end repeat
end if
else
make new folder at root_folder with properties {name:theType}
make new folder at (((root_folder as text) & (theType as text)) as alias) with properties {name:"Various"}
repeat with theFile in filNames
set aFile to (get every item of root_folder whose name is (theFile as string) and kind is "Folder")
try
move aFile to folder ((root_folder as text) & (theType as text) & ":" & "Various")
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for Folder:" & (theFile as string) & return & return & "N.B. All Contents will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (theType as text) & ":" & "Various") with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for Folder:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
end repeat
end if
else
display dialog theUser & ", the Process has been Cancelled!" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
end if
end if
end repeat
display dialog theUser & ", Sort and Move is Complete!" & return & "Thanks for using this Script from Jonathan Feeke ([email protected])" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
else
set filNames to (choose from list fList with title my_title with prompt "Choose " & (chooseType as string) & " Files to Sort and Move: (multi-select)" & return & "(only select the one's that apply)" & return OK button name "Next" cancel button name "Cancel" with multiple selections allowed)
if filNames = false then
display dialog theUser & ", the Process has been Cancelled!" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
else
set myCheck to button returned of (display dialog "Confirm you want to:" & return & "Move " & (chooseType as string) & " Files to a New OR Existing Folder?" & return & return & "N.B. Folders are created within the Analyze Folder Chosen" & return buttons {"Yes", "No"} default button 2 with title my_title with icon caution)
if myCheck = "Yes" then
--work gets done here for folders
set myCheckFilter to button returned of (display dialog "Would you like to Create Individual Folders of Files for each Type" & return & "e.g. Each file Extension will have it's own Folder within the " & (chooseType as string) & " Folder" & return buttons {"Yes", "No"} default button 2 with title my_title with icon caution)
set typeList to {"Audio", "Movie", "Image"} as list
if myCheckFilter = "Yes" then
--work gets done here for folders
if ((chooseType as string) = "ALL (Audio,Movie,Image)") then
repeat with fileType in typeList
set chooseType to fileType
if ((chooseType as string) = "Audio") then
set filNamesFilter to {} as list
repeat with theFile in filNames
repeat with findExt in fileTypesAud
if (theFile contains findExt) then
set filNamesFilter to filNamesFilter & (theFile)
end if
end repeat
end repeat
else
if ((chooseType as string) = "Movie") then
set filNamesFilter to {} as list
repeat with theFile in filNames
repeat with findExt in fileTypesMov
if (theFile contains findExt) then
set filNamesFilter to filNamesFilter & (theFile)
end if
end repeat
end repeat
else
if ((chooseType as string) = "Image") then
set filNamesFilter to {} as list
repeat with theFile in filNames
repeat with findExt in fileTypesImg
if (theFile contains findExt) then
set filNamesFilter to filNamesFilter & (theFile)
end if
end repeat
end repeat
end if
end if
end if
repeat with theFile in filNamesFilter --filNames
set aExt to (get the name extension of every item of root_folder whose name is (theFile as string))
repeat with theExt in aExt
set myExt to theExt
if (exists folder chooseType of root_folder) is true then
if (exists folder myExt of (((root_folder as text) & (chooseType as text)) as alias)) is true then
set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (myExt as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (myExt as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
else
make new folder at ((root_folder as text) & (chooseType as text)) with properties {name:myExt}
set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (myExt as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (myExt as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
end if
else
make new folder at root_folder with properties {name:chooseType}
make new folder at ((root_folder as text) & (chooseType as text)) with properties {name:myExt}
set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (myExt as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (myExt as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
end if
end repeat
end repeat
end repeat
else
if ((chooseType as string) = "Software") then
repeat with theFile in filNames
set aExt to (get the name extension of every item of root_folder whose name is (theFile as string))
repeat with theExt in aExt
set myExt to theExt
set chooseType to (chooseType as string)
set chooseTypeSof to (chooseTypeSof as string)
if (exists folder chooseType of root_folder) is true then
if (exists folder chooseTypeSof of (((root_folder as text) & (chooseType as text)) as alias)) is true then
if (exists folder myExt of (((root_folder as text) & (chooseType as text) & ":" & (chooseTypeSof as text)) as alias)) is true then
set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (chooseTypeSof as text) & ":" & (myExt as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (chooseTypeSof as text) & ":" & (myExt as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
else
make new folder at ((root_folder as text) & (chooseType as text) & ":" & (chooseTypeSof as text)) with properties {name:aExt}
set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (chooseTypeSof as text) & ":" & (myExt as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (chooseTypeSof as text) & ":" & (myExt as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
end if
else
make new folder at ((root_folder as text) & (chooseType as text)) with properties {name:chooseTypeSof}
make new folder at ((root_folder as text) & (chooseType as text) & ":" & (chooseTypeSof as text)) with properties {name:myExt}
set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (chooseTypeSof as text) & ":" & (myExt as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (chooseTypeSof as text) & ":" & (myExt as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
end if
else
make new folder at root_folder with properties {name:chooseType}
make new folder at ((root_folder as text) & (chooseType as text)) with properties {name:chooseTypeSof}
make new folder at ((root_folder as text) & (chooseType as text) & ":" & (chooseTypeSof as text)) with properties {name:myExt}
set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (chooseTypeSof as text) & ":" & (myExt as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (chooseTypeSof as text) & ":" & (myExt as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
end if
end repeat
end repeat
else
if ((chooseType as string) = "Movie") then
repeat with theFile in filNames
set aExt to (get the name extension of every item of root_folder whose name is (theFile as string))
set aLetter to ((characters 1 thru 1 of (theFile as string)) as string)
set alphaList to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
set numList to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
ignoring case
repeat with alphaLetter in alphaList
if (alphaLetter as string) = (aLetter as string) then
set aLetter to alphaLetter
end if
end repeat
repeat with numLetter in numList
if (numLetter as string) = (aLetter as string) then
set aLetter to "0-9"
end if
end repeat
end ignoring
repeat with theExt in aExt
set myExt to theExt
set chooseType to (chooseType as string)
if (exists folder chooseType of root_folder) is true then
if (exists folder aLetter of (((root_folder as text) & (chooseType as text)) as alias)) is true then
if (exists folder myExt of (((root_folder as text) & (chooseType as text) & ":" & (aLetter as text)) as alias)) is true then
set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (aLetter as text) & ":" & (myExt as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (aLetter as text) & ":" & (myExt as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
else
make new folder at ((root_folder as text) & (chooseType as text) & ":" & (aLetter as text)) with properties {name:myExt}
set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (aLetter as text) & ":" & (myExt as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (aLetter as text) & ":" & (myExt as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
end if
else
make new folder at ((root_folder as text) & (chooseType as text)) with properties {name:aLetter}
make new folder at ((root_folder as text) & (chooseType as text) & ":" & (aLetter as text)) with properties {name:myExt}
set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (aLetter as text) & ":" & (myExt as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (aLetter as text) & ":" & (myExt as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
end if
else
make new folder at root_folder with properties {name:chooseType}
make new folder at ((root_folder as text) & (chooseType as text)) with properties {name:aLetter}
make new folder at ((root_folder as text) & (chooseType as text) & ":" & (aLetter as text)) with properties {name:myExt}
set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (aLetter as text) & ":" & (myExt as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (aLetter as text) & ":" & (myExt as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
end if
end repeat
end repeat
else
if ((chooseType as string) = "Image") then
repeat with aGroup in filNames
set aGroup to (get every item of root_folder whose name is in filNames)
end repeat
--repeat with theFile in filNames
repeat with theFile in aGroup
set aFile to theFile
--set aFile to (get every item of root_folder whose name is (theFile as string))
set aExt to (get the name extension of (aFile as alias))
--set aExt to (get the name extension of every item of root_folder whose name is (theFile as string))
--repeat with theExt in aExt
--set myExt to theExt
set myExt to aExt
set chooseType to (chooseType as string)
if (exists folder chooseType of root_folder) is true then
if (exists folder myExt of (((root_folder as text) & (chooseType as text)) as alias)) is true then
--set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (myExt as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (myExt as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
else
make new folder at ((root_folder as text) & (chooseType as text)) with properties {name:myExt}
--set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (myExt as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (myExt as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
end if
else
make new folder at root_folder with properties {name:chooseType}
make new folder at ((root_folder as text) & (chooseType as text)) with properties {name:myExt}
--set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (myExt as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (myExt as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
end if
--end repeat
end repeat
else --Music Videos
repeat with aGroup in filNames
set aGroup to (get every item of root_folder whose name is in filNames)
end repeat
--repeat with theFile in filNames
repeat with theFile in aGroup
set aFile to theFile
--set aFile to (get every item of root_folder whose name is (theFile as string))
set aExt to (get the name extension of (aFile as alias))
--set aExt to (get the name extension of every item of root_folder whose name is (theFile as string))
--repeat with theExt in aExt
--set myExt to theExt
set myExt to aExt
set chooseType to (chooseType as string)
if (exists folder chooseType of root_folder) is true then
if (exists folder myExt of (((root_folder as text) & (chooseType as text)) as alias)) is true then
--set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (myExt as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (myExt as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
else
make new folder at ((root_folder as text) & (chooseType as text)) with properties {name:myExt}
--set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (myExt as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (myExt as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
end if
else
make new folder at root_folder with properties {name:chooseType}
make new folder at ((root_folder as text) & (chooseType as text)) with properties {name:myExt}
--set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (myExt as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (myExt as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
end if
--end repeat
end repeat
end if
end if
end if
end if
else
if ((chooseType as string) = "ALL (Audio,Movie,Image)") then
repeat with fileType in typeList
set chooseType to fileType
repeat with theFile in filNames
if (exists folder chooseType of root_folder) is true then
set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (myExt as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
else
make new folder at root_folder with properties {name:chooseType}
set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (myExt as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
end if
end repeat
end repeat
else
if ((chooseType as string) = "Software") then
set chooseType to (chooseType as string)
set chooseTypeSof to (chooseTypeSof as string)
repeat with theFile in filNames
if (exists folder chooseType of root_folder) is true then
if (exists folder chooseTypeSof of (((root_folder as text) & (chooseType as text)) as alias)) is true then
set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (chooseTypeSof as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (chooseTypeSof as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
else
make new folder at ((root_folder as text) & (chooseType as text)) with properties {name:chooseTypeSof}
set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (chooseTypeSof as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (chooseTypeSof as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
end if
else
make new folder at root_folder with properties {name:chooseType}
make new folder at ((root_folder as text) & (chooseType as text)) with properties {name:chooseTypeSof}
set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (chooseTypeSof as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (chooseTypeSof as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
end if
end repeat
else
if ((chooseType as string) = "Movie") then
set chooseType to (chooseType as string)
repeat with theFile in filNames
set aLetter to ((characters 1 thru 1 of (theFile as string)) as string)
set alphaList to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
ignoring case
repeat with alphaLetter in alphaList
if (alphaLetter as string) = (aLetter as string) then
set aLetter to alphaLetter
end if
end repeat
end ignoring
if (exists folder chooseType of root_folder) is true then
if (exists folder aLetter of (((root_folder as text) & (chooseType as text)) as alias)) is true then
set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (aLetter as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (chooseTypeSof as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
else
make new folder at ((root_folder as text) & (chooseType as text)) with properties {name:aLetter}
set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (aLetter as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (chooseTypeSof as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
end if
else
make new folder at root_folder with properties {name:chooseType}
make new folder at ((root_folder as text) & (chooseType as text)) with properties {name:aLetter}
set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (aLetter as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text) & ":" & (chooseTypeSof as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
end if
end repeat
else
if ((chooseType as string) = "Movie") then
repeat with theFile in filNames
set chooseType to (chooseType as string)
if (exists folder chooseType of root_folder) is true then
set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
else
make new folder at root_folder with properties {name:chooseType}
set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
end if
end repeat
else --Music Videos
repeat with theFile in filNames
set chooseType to (chooseType as string)
if (exists folder chooseType of root_folder) is true then
set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
else
make new folder at root_folder with properties {name:chooseType}
set aFile to (get every item of root_folder whose name is (theFile as string))
try
move aFile to folder ((root_folder as text) & (chooseType as text))
on error error_message number error_number
if (error_number = -15267) then
beep
set canDo to button returned of (display dialog error_message & " for File:" & (theFile as string) & return & return & "N.B. File will be OVERWRITTEN" & return & "Would you like to Overwrite?" buttons {"Yes", "No"} default button 2 with title my_title with icon caution giving up after 30)
if (canDo = "Yes") then
move aFile to folder ((root_folder as text) & (chooseType as text)) with replacing
else
display dialog (theFile as string) & " will not be Moved." buttons {"Ok"} default button 1 with title my_title with icon caution giving up after 5
end if
else
beep
display dialog error_message & " for File:" & (theFile as string) buttons {"Cancel"} default button 1 with title my_title with icon caution giving up after 30
end if
end try
end if
end repeat
end if
end if
end if
end if
end if
else
display dialog theUser & ", the Process has been Cancelled!" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
end if
display dialog theUser & ", Sort and Move is Complete!" & return & "Thanks for using this Script from Jonathan Feeke ([email protected])" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
end if
end if
end try
end if
end tell
end if
end if
--##########################################
if sel is not {} then
--##########################################
if myChoice = "Listen and Edit" then
set opt to button returned of (display dialog "Would you like to Listen and Edit?" & return & "What this Function Does:" & return & "-Plays a Track so you can Listen to it" & return & "-Asks for a Track Artist and Track Name" & return & "-Updates the Track Artist and Track Name Tag" & return & return & (count sel) & " Track(s) Selected" buttons {"Yes", "No"} default button 2 with title my_title with icon 1 giving up after 60)
if opt = "Yes" then
--to speed up this process i will prefind all the playlists needed as this process does not change any playlists
repeat with this_track in sel
play this_track
set player position to 1
set player position to (get player position) + (60)
set inputText1 to text returned of (display dialog "Artist Name:" default answer (this_track's artist as text))
set inputText2 to text returned of (display dialog "Track Name:" default answer (this_track's name as text))
if (inputText1 = "" or inputText1 = false or inputText2 = "" or inputText2 = false) then
display dialog theUser & ", the Process has been Cancelled!" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
else
set optConfirm to (display dialog "Edit Track Tags to:" & return & "Artist: " & (inputText1 as text) & return & "Name: " & (inputText1 as text) & " - " & (inputText2 as text) & return buttons {"Cancel", "Proceed"} default button 1 with title my_title with icon 1 giving up after 60)
if optConfirm = true then
tell this_track to set name to (inputText1 as text) & " - " & (inputText2 as text)
tell this_track to set artist to (inputText1 as text)
end if
end if
end repeat
display dialog theUser & ", Listen and Edit is Complete!" & return & "Thanks for using this Script from Jonathan Feeke ([email protected])" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
end if
end if
--##########################################
set myChoice1 to button returned of (display dialog "Choose which process you would like to run: (Part 3)" & return & return buttons {"Create Playlists", "Super Clean", "Track Playlist Cleaner"} default button 1 with title my_title with icon caution)
--##########################################
if myChoice1 = "Create Playlists" then
--##########################################
set myChoicePlaylistSort to button returned of (display dialog "Would you like to Create NEW Playlists by Artist Name and Album from the Current FULL Playlist?" & return & "N.B: Creates Playlists Automatically from the Artists OR Album OR Artist(Album) Choice then creates a copy OR move(if Playlist already Exists) of those related Tracks from current Playlist. The Process then Moves the Playlist to the Compilations OR DJ Compilations Playlist Folder" & return buttons {"Yes", "No"} default button 2 with title my_title with icon 1)
if myChoicePlaylistSort = "Yes" then
set optConfirm to button returned of (display dialog "Choose a Type to Group by:" & return & return buttons {"Artist", "Album", "Artist (Album)"} default button 1 with title my_title with icon 1 giving up after 60)
set optConfirm1 to button returned of (display dialog "Choose Location to Move to:" & return & return buttons {"Compilations", "DJ Compilations"} default button 1 with title my_title with icon 1 giving up after 60)
if optConfirm = "Artist (Album)" then
display dialog ("You have chosen Artist (Album). If the Artists vary the Process with use Various Artists as the Name") with title my_title giving up after 5
end if
-- get selected playlist and source
try
set fx to fixed indexing
set fixed indexing to true
set thisPlaylist to (a reference to (get view of front window))
if selection is not {} then --test if there is a selection
set using_selection to true
set idx to (count selection's items)
else --it's the whole playlist
set selectedTracks to (get a reference to thisPlaylist)
set using_selection to false
set idx to (count thisPlaylist's tracks)
end if
set thisPlaylist to view of front window
set thisSource to container of thisPlaylist
on error
display dialog "You must select a Playlist first." buttons {"Ok"} default button 1 with title my_title with icon 2
return
end try
-- for dialog
set srcname to "iTunes"
if kind of thisSource is iPod then set srcname to "iPod"
-- advise about main library if selected
if class of thisPlaylist is library playlist then
display dialog "You have selected the " & srcname & " main library. Processing this many Artists could take several minutes..." buttons {"Ok"} with title my_title with icon 2
end if
display dialog "Please Wait one moment to gather info…wait for this process to complete" buttons {""} with title my_title giving up after 5
-- get Artist names
with timeout of 30000 seconds
try
set allArts to {}
if optConfirm = "Artist" then
repeat with j from 1 to idx
if using_selection then
set thisTrack to item j of selection
else
set thisTrack to track j of selectedTracks
end if
set allArts to (artist of thisTrack) & allArts
end repeat
--set allArts to (artist of tracks of thisPlaylist)
else
repeat with j from 1 to idx
if using_selection then
set thisTrack to item j of selection
else
set thisTrack to track j of selectedTracks
end if
set allArts to (album of thisTrack) & allArts
end repeat
--set allArts to (album of tracks of thisPlaylist)
end if
on error n
set fixed indexing to fx
display dialog (n & return & return & "Advice: Select another Playlist.") with title my_title giving up after 10
end try
end timeout
-- get discrete list of Artists in the Playlist
set allArts to my get_discrete_list_of(allArts)
-- init
set theseTracks to {}
-- this is the routine that gets the tracks
-- for each of the Artists
with timeout of 30000 seconds
repeat with anA in allArts
if optConfirm = "Artist" then
repeat with j from 1 to idx
if using_selection then
set thisTrack to item j of selection
else
set thisTrack to track j of selectedTracks
end if
if thisTrack's artist is anA then
set theseTracks to theseTracks & thisTrack
end if
end repeat
--set theseTracks to (every track of thisPlaylist whose artist is anA)
else
repeat with j from 1 to idx
if using_selection then
set thisTrack to item j of selection
else
set thisTrack to track j of selectedTracks
end if
if thisTrack's album is anA then
set theseTracks to theseTracks & thisTrack
end if
end repeat
--set theseTracks to (every track of thisPlaylist whose album is anA)
end if
-- get name for new Playlist from user
set newPlaylistName to anA
-- make new Playlist; if it already exists, clear the tracks
if not (exists playlist newPlaylistName of thisSource) then
set newPlaylist to make new user playlist at thisSource with properties {name:newPlaylistName}
else
set newPlaylist to user playlist newPlaylistName of thisSource
if optConfirm1 = "Compilations" then
move newPlaylist to some folder playlist whose name is "Compilations"
else
move newPlaylist to some folder playlist whose name is "DJ Compilations"
end if
--delete tracks of newPlaylist
--THIS PROCESS COULD ADD DUPLICATES IF YOU RE-PROCESS
end if
set myArtAlb to ""
-- copy tracks to the new Playlist
repeat with aTr in theseTracks
set myartist to (get artist of aTr)
set myalbum to (get album of aTr)
set dbid to (get database ID of aTr)
if not (exists (some track of newPlaylist whose database ID is dbid)) then
duplicate aTr to newPlaylist
end if
if myArtAlb = "" then
myArtAlb = myartist & " (" & myalbum & ")"
else
if myArtAlb = myartist & " (" & myalbum & ")" then
--do nothing as it matches
else
set myArtAlb to "Various Artists"
end if
end if
end repeat
--rename the Playlist if the user wants it to be Artist and Album
if optConfirm = "Artist (Album)" then
set name of newPlaylist to myArtAlb
end if
end repeat
end timeout
set fixed indexing to fx
display dialog theUser & "," & "This Process is Complete!" & return & "Thanks for using this Script from Jonathan Feeke ([email protected])" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
--else, you done
return
end if
end if
--##########################################
if myChoice1 = "Super Clean" then
set mySuperClean to button returned of (display dialog "Would you like to use the Super Clean Tool?" & return & "N.B: This Fixes a variety of Text Naming Conventions for Later use with the Clean Tool, and uses a lot of user input. This process will be time consuming if you select many tracks and only cleans the Artist and Name Tags" & return buttons {"Yes", "No"} default button 2 with title my_title with icon 1)
if mySuperClean = "Yes" then
set total_count to ((count sel) + 1)
set iteration to 1
set ofi to fixed indexing
set fixed indexing to true
with timeout of 300000 seconds
repeat with this_track in sel
if iteration is less than total_count then
set main_string to "DJ Jonny F is Processing your Selection"
set sub_string to ("Processing Track " & (iteration as string) & " of " & ((total_count - 1) as string) & "...")
my display_progress(iteration, total_count - 1, main_string, sub_string)
--do something
set thetxtfile to (this_track's name) as Unicode text
ignoring case
try
set myFileName to (this_track's name) as Unicode text
set myArtistName to (this_track's artist) as Unicode text
considering case
set AppleScript's text item delimiters to {"-"}
set pList to {} as list
--if (count myFileName's text items) > 2 then
set pList to words of myFileName
set opt1 to (choose from list pList with title my_title with prompt ¬
(("Choose a Artist: (multi-select)" & return & "(cancel if the artist is not in the Name)" & return & "Artist: " & myArtistName as string) & return & "Name: " & myFileName as string) & return OK button name ¬
"Next" cancel button name "Cancel" with multiple selections allowed)
set opt2 to (choose from list pList with title my_title with prompt ¬
(("Choose a Name: (multi-select)" & return & "Artist: " & myArtistName as string) & return & "Name: " & myFileName as string) & return OK button name ¬
"Next" cancel button name "Cancel" with multiple selections allowed)
set opt3 to (choose from list pList with title my_title with prompt ¬
(("Choose any Bracketed Text: (multi-select)" & return & "e.g. (Remix By etc)" & return & "Artist: " & myArtistName as string) & return & "Name: " & myFileName as string) & return OK button name ¬
"Next" cancel button name "Cancel" with multiple selections allowed)
set AppleScript's text item delimiters to {""}
set AppleScript's text item delimiters to space
set theArtist to opt1 as string
set theTrack to opt2 as string
set theBracket to opt3 as string
set AppleScript's text item delimiters to {""}
if opt2 is false then
display dialog return & "This Track will not be edited as you have not Selected a Track Name" buttons {"Ok"} default button 1 with icon 1 giving up after 10 with title my_title
else
if opt1 is false then
set theArtist to myArtistName as string
if opt3 is false then
set theName to theArtist & " - " & theTrack
else
set theName to theArtist & " - " & theTrack & " (" & theBracket & ")"
end if
else
if opt3 is false then
set theName to theArtist & " - " & theTrack
else
set theName to theArtist & " - " & theTrack & " (" & theBracket & ")"
end if
end if
end if
tell this_track to set name to theName
--end if
end considering
end try
end ignoring
--end of do something
set iteration to (iteration + 1)
end if
end repeat
end timeout
set fixed indexing to ofi
display dialog theUser & "," & " Your Selection has been Super Cleaned! This Process is Complete!" & return & "Thanks for using this Script from Jonathan Feeke ([email protected])" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
end if
end if
--##########################################
--##########################################
if myChoice1 = "Track Playlist Cleaner" then
set myTracktoPlaylistDuplicated to button returned of (display dialog "Would you like to use the Track to Multi-Playlist Search and Remove?" & return & "N.B: This Fixes a Playlist that has a Track in Another Playlist, and uses user input. This process will be time consuming if you select many tracks" & return buttons {"Yes", "No"} default button 2 with title my_title with icon 1)
if myTracktoPlaylistDuplicated = "Yes" then
set total_count to ((count sel) + 1)
set iteration to 1
set ofi to fixed indexing
set fixed indexing to true
with timeout of 300000 seconds
repeat with this_track in sel
if iteration is less than total_count then
set main_string to "DJ Jonny F is Processing your Selection"
set sub_string to ("Processing Track " & (iteration as string) & " of " & ((total_count - 1) as string) & "...")
my display_progress(iteration, total_count - 1, main_string, sub_string)
--do something
set dbid to (get database ID of this_track)
set src to container of container of this_track
set playlist_list to {}
repeat with thisPlaylist in (get every user playlist of src)
if (exists (some track of thisPlaylist whose database ID is dbid)) then
set end of playlist_list to (get name of thisPlaylist)
end if
end repeat
if ((count items in playlist_list) > 2) then
play this_track
set player position to 1
set player position to (get player position) + (60)
set prmpt to ((get artist of this_track) & ": (" & (get name of this_track) & ")" & return & "N.B. Do not choose to Delete from the Main Music Playlist, it Removes it from your iTunes")
set res to (choose from list playlist_list with prompt prmpt default items {get name of current playlist} OK button name "Delete Track from this Playlist" cancel button name "Next") as string
stop this_track
if res is "false" then
--user cancelled so go to next track
else
repeat with thisPlaylistFix in (get every user playlist of src)
if (exists (some track of thisPlaylistFix whose database ID is dbid)) then
if ((get name of thisPlaylistFix) as text = res as text) then
set delete_this_track to (some track of thisPlaylistFix whose database ID is dbid)
delete (delete_this_track)
end if
end if
end repeat
end if
end if
--end of do something
set iteration to (iteration + 1)
end if
end repeat
end timeout
set fixed indexing to ofi
display dialog theUser & "," & " Track to Milti-Playlist Search and Remove Process Complete!" & return & "Thanks for using this Script from Jonathan Feeke ([email protected])" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
end if
end if
--##########################################
set myChoice2 to button returned of (display dialog "Choose which process you would like to run: (Part 4)" & return & return buttons {"Get Names and Update", "Listen and Move", "Final Clean"} default button 1 with title my_title with icon caution)
--##########################################
if myChoice2 = "Get Names and Update" then
set opt1 to button returned of (display dialog "Would you like to Get Names and Update?" & return & "What this Function Does:" & return & "-Merges Song Name with Comments" & return & "-Merges File Location with Description" & return & "-Replaces Song Name with Filename (The actual name of the Audio File, minus the extension)" & return & return & (count sel) & " Track(s) Selected" buttons {"Yes", "No"} default button 2 with title my_title with icon 1 giving up after 60)
if opt1 = "Yes" then
set total_count to ((count sel) + 1)
--set iteration to 1
--set old_fi to fixed indexing
--set fixed indexing to true
with timeout of 3000 seconds
repeat with this_track in sel
set this_track's grouping to "DIRTY"
set this_track's comment to (get this_track's name)
set this_track's description to "Orig. Location: (" & POSIX path of (get this_track's location) & ")"
--set this_track's name to my fix_filename(get this_track's location) --too slow
set addedFiles to addedFiles + 1
my progressNotice()
end repeat
end timeout
display dialog theUser & ", Get Names and Update is Complete!" & return & "Thanks for using this Script from Jonathan Feeke ([email protected])" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
end if
--##########################################
else if myChoice2 = "Listen and Move" then
set opt2 to button returned of (display dialog "Would you like to Listen and Move?" & return & "What this Function Does:" & return & "-Plays a Track so you can Listen to it" & return & "-Asks which Playlist you want to add the track to" & return & "-Copies the Track to that Playlist" & return & "-Deletes the Track from the Current Playlist" & return & return & (count sel) & " Track(s) Selected" buttons {"Yes", "No"} default button 2 with title my_title with icon 1 giving up after 60)
if opt2 = "Yes" then
--to speed up this process i will prefind all the playlists needed as this process does not change any playlists
set pListA to {} as list
set pListB to {} as list
repeat with this_track in sel
play this_track
set player position to 1
set player position to (get player position) + (60)
set dbid to (get database ID of this_track)
set src to container of container of this_track
set playlist_list to {}
set pFolder to "" as string
set pList to "" as string
set thisPlaylist to view of front window
set thisSource to container of thisPlaylist
--set pListA to {} as list
if pListB is {} then
repeat with thisPlaylist1 in (get every folder playlist of src)
if exists parent of thisPlaylist1 then
if (get name of parent of thisPlaylist1) as text = "DJ Jonny F" then
set pListB to pListB & (get name of thisPlaylist1)
end if
end if
end repeat
end if
set optA to (choose from list pListB with title my_title with prompt ¬
"Choose a Playlist Folder:" & return & "Track Time: " & this_track's time & return OK button name ¬
"Next" cancel button name "Cancel")
if (optA as text) = "false" then
--do nothing
exit repeat
else if (optA as text) = "Megamix" then
set player position to (get player position) + (1000)
set pListA to {} as list
repeat with thisPlaylist2 in (get every folder playlist of src)
if exists parent of thisPlaylist2 then
if parent of thisPlaylist2 is folder playlist ("Megamix") then
set pListA to pListA & (get name of thisPlaylist2)
else
--do nothing just yet
end if
end if
end repeat
set optA to (choose from list pListA with title my_title with prompt ¬
"Choose a Playlist Folder (Megamix):" OK button name ¬
"Next" cancel button name "Cancel")
set player position to (get player position) + (200)
set pListA to {} as list
repeat with thisPlaylist3 in (get every user playlist of src)
if exists parent of parent of thisPlaylist3 then
if (parent of parent of thisPlaylist3 is folder playlist ("Megamix")) and ((get name of parent of thisPlaylist3) as text = optA as text) then
set pListA to pListA & (get name of thisPlaylist3)
end if
end if
end repeat
set optB to (choose from list pListA with title my_title with prompt ¬
"Choose a Playlist to Move Track to:" OK button name ¬
"Move" cancel button name "Cancel")
set player position to (get player position) + (200)
repeat with thisPlaylist4 in (get every user playlist of src)
if exists parent of parent of thisPlaylist4 then
if (parent of parent of thisPlaylist4 is folder playlist ("Megamix")) and ((get name of parent of thisPlaylist4) as text = optA as text) then
if (optB as text) = (get name of thisPlaylist4) then
--duplicate (some track of library playlist 1 whose database ID is dbid) to thisPlaylist4
--duplicate this_track to thisPlaylist4
--delete this_track
end if
end if
end if
end repeat
else
set pListA to {} as list
repeat with thisPlaylist5 in (get every user playlist of src)
if exists parent of parent of thisPlaylist5 then
if (parent of parent of thisPlaylist5 is folder playlist ("DJ Jonny F")) and ((get name of parent of thisPlaylist5) as text = optA as text) then
set pListA to pListA & (get name of thisPlaylist5)
end if
end if
end repeat
set player position to (get player position) + (60)
set optB to (choose from list pListA with title my_title with prompt ¬
"Choose a Playlist to Move Track to:" OK button name ¬
"Move" cancel button name "Cancel")
repeat with thisPlaylist6 in (get every user playlist of src)
if exists parent of parent of thisPlaylist6 then
if (parent of parent of thisPlaylist6 is folder playlist ("DJ Jonny F")) and ((get name of parent of thisPlaylist6) as text = optA as text) then
if (optB as text) = (get name of thisPlaylist6) then
duplicate (some track of library playlist 1 whose database ID is dbid) to thisPlaylist6
--duplicate this_track to thisPlaylist6
--delete this_track
end if
end if
end if
end repeat
end if
end repeat
display dialog theUser & ", Listen and Move is Complete!" & return & "Thanks for using this Script from Jonathan Feeke ([email protected])" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
end if
else
--##########################################
--tell current application
-- say "Hello " & theUser & ", thank you for using the iTunes Repair tool, please check the processes properly before you continue."
--end tell
set opt3 to button returned of (display dialog "Would you like to Final Clean?" & return & "What this Function Does:" & return & "- Copy Playlist Name to Album" & return & "- Copy Folder Name to Album Artist" & return & "- Add Description to Comments" & return & "- Copy Folder Name to Genre" & return & "- Clear Track and Disc No's and Counts" & return & "- Fix Capitilization and Name" & return & "- Fix Rogue Characters" & return & "- Add Main Folder to Grouping" & return & "- Search Google(1) for and Embed Artwork" & return & return & "This process cannot be undone" & return & return & (count sel) & " Track(s) Selected" buttons {"Yes", "No"} default button 2 with title my_title with icon 1 giving up after 60)
if opt3 = "Yes" then
set myQuestion to button returned of (display dialog "Are your Artist Names in front of the Track Name?" & return & "This will stop asking you to choose the artist-name/name-artist flip" & return & return buttons {"Yes", "No"} default button 2 with title my_title with icon caution)
set total_count to ((count sel) + 1)
set iteration to 1
set myPesist to "Not"
set mypesistval to "Not"
set ofi to fixed indexing
set fixed indexing to true
with timeout of 300000 seconds
repeat with this_track in sel
set myFileName to ""
set newName to ""
if iteration is less than total_count then
set main_string to "DJ Jonny F is Processing your Selection"
set sub_string to ("Processing Track " & (iteration as string) & " of " & ((total_count - 1) as string) & "...")
my display_progress(iteration, total_count - 1, main_string, sub_string)
--do something
--EDIT TRACK TAGS
set dbid to (get database ID of this_track)
set src to container of container of this_track
set playlist_list to {}
set pFolder to "" as string
set pList to "" as string
set pCount to 0
repeat with thisPlaylist in (get every folder playlist of src)
if (exists (some track of thisPlaylist whose database ID is dbid)) then
set end of playlist_list to (get name of thisPlaylist)
set pCount to (pCount + 1)
if pCount is 2 then
set pFolder to (get name of thisPlaylist)
end if
end if
end repeat
set pCount to 0
repeat with thisPlaylist in (get every user playlist of src)
if (exists (some track of thisPlaylist whose database ID is dbid)) then
set end of playlist_list to (get name of thisPlaylist)
set pCount to (pCount + 1)
if pCount is 2 then
set pList to (get name of thisPlaylist)
end if
end if
end repeat
set pOldAlbum to (get this_track's album)
set pOldAlbumArtist to (get this_track's album artist)
--the next few steps clean any funny characters and formatting
set thetxtfile to (this_track's name) as Unicode text
ignoring case
set thetxtfile to my findAndReplace("( ", "(", thetxtfile)
set thetxtfile to my findAndReplace(" )", ")", thetxtfile)
set thetxtfile to my findAndReplace("(", " (", thetxtfile)
set thetxtfile to my findAndReplace("[", " (", thetxtfile)
set thetxtfile to my findAndReplace("<", " (", thetxtfile)
set thetxtfile to my findAndReplace(">", " )", thetxtfile)
set thetxtfile to my findAndReplace("]", ")", thetxtfile)
set thetxtfile to my findAndReplace("_", " ", thetxtfile)
set thetxtfile to my findAndReplace("--", " - ", thetxtfile)
set thetxtfile to my findAndReplace(" -", "-", thetxtfile)
set thetxtfile to my findAndReplace("- ", "-", thetxtfile)
set thetxtfile to my findAndReplace("-", " - ", thetxtfile)
set thetxtfile to my findAndReplace("--", " - ", thetxtfile)
set thetxtfile to my findAndReplace(" &", "&", thetxtfile)
set thetxtfile to my findAndReplace("& ", "&", thetxtfile)
set thetxtfile to my findAndReplace("&", " & ", thetxtfile)
set thetxtfile to my findAndReplace(".mp3", "", thetxtfile)
set thetxtfile to my findAndReplace(".mp4", "", thetxtfile)
set thetxtfile to my findAndReplace(".wmv", "", thetxtfile)
set thetxtfile to my findAndReplace(".flv", "", thetxtfile)
set thetxtfile to my findAndReplace("Ft.", "feat.", thetxtfile)
set thetxtfile to my findAndReplace(" ", " ", thetxtfile)
set thetxtfile to my findAndReplace(" ", " ", thetxtfile)
set thetxtfile to my findAndReplace(" ", " ", thetxtfile)
set thetxtfile to my findAndReplace(" ", " ", thetxtfile)
set thetxtfile to my findAndReplace(" ", " ", thetxtfile)
end ignoring
tell this_track to set name to thetxtfile
set thetxtfile to (this_track's artist) as Unicode text
ignoring case
set thetxtfile to my findAndReplace("( ", "(", thetxtfile)
set thetxtfile to my findAndReplace(" )", ")", thetxtfile)
set thetxtfile to my findAndReplace("(", " (", thetxtfile)
set thetxtfile to my findAndReplace("[", " (", thetxtfile)
set thetxtfile to my findAndReplace("<", " (", thetxtfile)
set thetxtfile to my findAndReplace(">", " )", thetxtfile)
set thetxtfile to my findAndReplace("]", ")", thetxtfile)
set thetxtfile to my findAndReplace("_", " ", thetxtfile)
set thetxtfile to my findAndReplace("-", " ", thetxtfile)
set thetxtfile to my findAndReplace(" &", "&", thetxtfile)
set thetxtfile to my findAndReplace("& ", "&", thetxtfile)
set thetxtfile to my findAndReplace("&", " & ", thetxtfile)
set thetxtfile to my findAndReplace(".mp3", "", thetxtfile)
set thetxtfile to my findAndReplace(".mp4", "", thetxtfile)
set thetxtfile to my findAndReplace(".wmv", "", thetxtfile)
set thetxtfile to my findAndReplace(".flv", "", thetxtfile)
set thetxtfile to my findAndReplace("Ft.", "feat.", thetxtfile)
set thetxtfile to my findAndReplace(" ", " ", thetxtfile)
set thetxtfile to my findAndReplace(" ", " ", thetxtfile)
set thetxtfile to my findAndReplace(" ", " ", thetxtfile)
set thetxtfile to my findAndReplace(" ", " ", thetxtfile)
set thetxtfile to my findAndReplace(" ", " ", thetxtfile)
end ignoring
tell this_track to set artist to thetxtfile
try
if (this_track's artist = "") then
set myFileName to (this_track's name) as Unicode text
considering case
set AppleScript's text item delimiters to "-"
if (count myFileName's text items) = 2 then
if myPesist = "Yes" then
if mypesistval = "Opt 1" then
set newName to ((text item 2 of myFileName as string) & " - " & (text item 1 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 2 of myFileName as string)
else if mypesistval = "Opt 2" then
set newName to ((text item 1 of myFileName as string) & " - " & (text item 2 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 1 of myFileName as string)
end if
else
set myNewVal to button returned of (display dialog "Options:" & return & return & "1: " & ((text item 2 of myFileName as string) & " - " & (text item 1 of myFileName as string)) & return & "2: " & ((text item 1 of myFileName as string) & " - " & (text item 2 of myFileName as string)) & return & return buttons {"Opt 1", "Opt 2"} default button 2 with title my_title with icon caution)
if myNewVal = "Opt 1" then
set newName to ((text item 2 of myFileName as string) & " - " & (text item 1 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 2 of myFileName as string)
set mypesistval to "Opt 1"
else if myNewVal = "Opt 2" then
set newName to ((text item 1 of myFileName as string) & " - " & (text item 2 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 1 of myFileName as string)
set mypesistval to "Opt 2"
end if
if myPesist = "Not" then
set myPesist to button returned of (display dialog "(ONE TIME QUESTION)" & return & return & "Would you like to Keep using " & myNewVal & " for the remaining Tracks?" & return & return buttons {"Yes", "No"} default button 2 with title my_title with icon caution)
end if
end if
else if (count myFileName's text items) > 3 then
set myNewVal to button returned of (display dialog "Options:" & return & return & "1: " & ((text item 1 of myFileName as string) & " - " & (text item 2 of myFileName as string)) & return & "2: " & ((text item 2 of myFileName as string) & " - " & (text item 3 of myFileName as string)) & return & return buttons {"Opt 1", "Opt 2", "Next"} default button 2 with title my_title with icon caution)
if myNewVal = "Next" then
set myNewVal to button returned of (display dialog "Options:" & return & return & "1: " & ((text item 2 of myFileName as string) & " - " & (text item 3 of myFileName as string)) & return & "2: " & ((text item 3 of myFileName as string) & " - " & (text item 4 of myFileName as string)) & return & "3: " & ((text item 2 of myFileName as string) & " - " & (text item 4 of myFileName as string)) & return & return buttons {"Opt 1", "Opt 2", "Opt 3"} default button 1 with title my_title with icon caution)
if myNewVal = "Opt 1" then
set newName to ((text item 2 of myFileName as string) & " - " & (text item 3 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 2 of myFileName as string)
else if myNewVal = "Opt 2" then
set newName to ((text item 3 of myFileName as string) & " - " & (text item 4 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 3 of myFileName as string)
else if myNewVal = "Opt 3" then
set newName to ((text item 2 of myFileName as string) & " - " & (text item 4 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 2 of myFileName as string)
end if
else if myNewVal = "Opt 1" then
set newName to ((text item 1 of myFileName as string) & " - " & (text item 2 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 1 of myFileName as string)
else if myNewVal = "Opt 2" then
set newName to ((text item 2 of myFileName as string) & " - " & (text item 3 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 2 of myFileName as string)
end if
else if (count myFileName's text items) > 2 then
set myNewVal to button returned of (display dialog "Options:" & return & return & "1: " & ((text item 1 of myFileName as string) & " - " & (text item 2 of myFileName as string)) & return & "2: " & ((text item 2 of myFileName as string) & " - " & (text item 3 of myFileName as string)) & return & "3: " & ((text item 1 of myFileName as string) & " - " & (text item 3 of myFileName as string)) & return & return buttons {"Opt 1", "Opt 2", "Opt 3"} default button 1 with title my_title with icon caution)
if myNewVal = "Opt 1" then
set newName to ((text item 1 of myFileName as string) & " - " & (text item 2 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 1 of myFileName as string)
else if myNewVal = "Opt 2" then
set newName to ((text item 2 of myFileName as string) & " - " & (text item 3 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 2 of myFileName as string)
else if myNewVal = "Opt 3" then
set newName to ((text item 1 of myFileName as string) & " - " & (text item 3 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 1 of myFileName as string)
end if
else
set myNewVal to button returned of (display dialog "Options:" & return & return & "1: " & ("Unknown Artist - " & (text item 1 of myFileName as string)) & return & "2: " & ((text item 1 of myFileName as string) & " - Unknown Track") & return & return buttons {"Opt 1", "Opt 2"} default button 2 with title my_title with icon caution)
if myNewVal = "Opt 1" then
set newName to ("Unknown Artist - " & (text item 1 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to ("Unknown Artist")
else if myNewVal = "Opt 2" then
set newName to ((text item 1 of myFileName as string) & " - Unknown Track") as string
tell this_track to set name to newName
tell this_track to set artist to (text item 2 of myFileName as string)
end if
end if
end considering
else
if this_track's name contains this_track's artist then
set myFileName to (this_track's name) as Unicode text
considering case
set AppleScript's text item delimiters to "-"
if (count myFileName's text items) = 2 then
--do nothing as the format is already correct
else if (count myFileName's text items) > 3 then
set myNewVal to button returned of (display dialog "Options:" & return & return & "1: " & ((text item 1 of myFileName as string) & " - " & (text item 2 of myFileName as string)) & return & "2: " & ((text item 2 of myFileName as string) & " - " & (text item 3 of myFileName as string)) & return & return buttons {"Opt 1", "Opt 2", "Next"} default button 2 with title my_title with icon caution)
if myNewVal = "Next" then
set myNewVal to button returned of (display dialog "Options:" & return & return & "1: " & ((text item 2 of myFileName as string) & " - " & (text item 3 of myFileName as string)) & return & "2: " & ((text item 3 of myFileName as string) & " - " & (text item 4 of myFileName as string)) & return & "3: " & ((text item 2 of myFileName as string) & " - " & (text item 4 of myFileName as string)) & return & return buttons {"Opt 1", "Opt 2", "Opt 3"} default button 1 with title my_title with icon caution)
if myNewVal = "Opt 1" then
set newName to ((text item 2 of myFileName as string) & " - " & (text item 3 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 2 of myFileName as string)
else if myNewVal = "Opt 2" then
set newName to ((text item 3 of myFileName as string) & " - " & (text item 4 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 3 of myFileName as string)
else if myNewVal = "Opt 3" then
set newName to ((text item 2 of myFileName as string) & " - " & (text item 4 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 2 of myFileName as string)
end if
else if myNewVal = "Opt 1" then
set newName to ((text item 1 of myFileName as string) & " - " & (text item 2 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 1 of myFileName as string)
else if myNewVal = "Opt 2" then
set newName to ((text item 2 of myFileName as string) & " - " & (text item 3 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 2 of myFileName as string)
end if
else if (count myFileName's text items) > 2 then
set myNewVal to button returned of (display dialog "Options:" & return & return & "1: " & ((text item 1 of myFileName as string) & " - " & (text item 2 of myFileName as string)) & return & "2: " & ((text item 2 of myFileName as string) & " - " & (text item 3 of myFileName as string)) & return & "3: " & ((text item 1 of myFileName as string) & " - " & (text item 3 of myFileName as string)) & return & return buttons {"Opt 1", "Opt 2", "Opt 3"} default button 1 with title my_title with icon caution)
if myNewVal = "Opt 1" then
set newName to ((text item 1 of myFileName as string) & " - " & (text item 2 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 1 of myFileName as string)
else if myNewVal = "Opt 2" then
set newName to ((text item 2 of myFileName as string) & " - " & (text item 3 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 2 of myFileName as string)
else if myNewVal = "Opt 3" then
set newName to ((text item 1 of myFileName as string) & " - " & (text item 3 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 1 of myFileName as string)
end if
else
set myNewVal to button returned of (display dialog "Options:" & return & return & "1: " & ("Unknown Artist - " & (text item 1 of myFileName as string)) & return & "2: " & ((text item 1 of myFileName as string) & " - Unknown Track") & return & return buttons {"Opt 1", "Opt 2"} default button 2 with title my_title with icon caution)
if myNewVal = "Opt 1" then
set newName to ("Unknown Artist - " & (text item 1 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to ("Unknown Artist")
else if myNewVal = "Opt 2" then
set newName to ((text item 1 of myFileName as string) & " - Unknown Track") as string
tell this_track to set name to newName
tell this_track to set artist to (text item 2 of myFileName as string)
end if
end if
end considering
else
if this_track's name contains "-" then
if button returned of (display dialog "It is Possible a Different Artist already Exists in the Name?" & return & return & "Would you like to Keep:" & return & "Artist: " & this_track's artist & return & "Name: " & this_track's name & return & return buttons {"Keep Artist", "Keep Artist from Name"} default button 2 with title my_title with icon caution) is "Keep Artist from Name" then
set myFileName to (this_track's name) as Unicode text
considering case
set AppleScript's text item delimiters to "-"
if (count myFileName's text items) > 3 then
set myNewVal to button returned of (display dialog "Options:" & return & return & "1: " & ((text item 1 of myFileName as string) & " - " & (text item 2 of myFileName as string)) & return & "2: " & ((text item 2 of myFileName as string) & " - " & (text item 3 of myFileName as string)) & return & return buttons {"Opt 1", "Opt 2", "Next"} default button 2 with title my_title with icon caution)
if myNewVal = "Next" then
set myNewVal to button returned of (display dialog "Options:" & return & return & "1: " & ((text item 2 of myFileName as string) & " - " & (text item 3 of myFileName as string)) & return & "2: " & ((text item 3 of myFileName as string) & " - " & (text item 4 of myFileName as string)) & return & "3: " & ((text item 2 of myFileName as string) & " - " & (text item 4 of myFileName as string)) & return & return buttons {"Opt 1", "Opt 2", "Opt 3"} default button 1 with title my_title with icon caution)
if myNewVal = "Opt 1" then
set newName to ((text item 2 of myFileName as string) & " - " & (text item 3 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 2 of myFileName as string)
else if myNewVal = "Opt 2" then
set newName to ((text item 3 of myFileName as string) & " - " & (text item 4 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 3 of myFileName as string)
else if myNewVal = "Opt 3" then
set newName to ((text item 2 of myFileName as string) & " - " & (text item 4 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 2 of myFileName as string)
end if
else if myNewVal = "Opt 1" then
set newName to ((text item 1 of myFileName as string) & " - " & (text item 2 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 1 of myFileName as string)
else if myNewVal = "Opt 2" then
set newName to ((text item 2 of myFileName as string) & " - " & (text item 3 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 2 of myFileName as string)
end if
else if (count myFileName's text items) > 2 then
set myNewVal to button returned of (display dialog "Options:" & return & return & "1: " & ((text item 1 of myFileName as string) & " - " & (text item 2 of myFileName as string)) & return & "2: " & ((text item 2 of myFileName as string) & " - " & (text item 3 of myFileName as string)) & return & "3: " & ((text item 1 of myFileName as string) & " - " & (text item 3 of myFileName as string)) & return & return buttons {"Opt 1", "Opt 2", "Opt 3"} default button 1 with title my_title with icon caution)
if myNewVal = "Opt 1" then
set newName to ((text item 1 of myFileName as string) & " - " & (text item 2 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 1 of myFileName as string)
else if myNewVal = "Opt 2" then
set newName to ((text item 2 of myFileName as string) & " - " & (text item 3 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 2 of myFileName as string)
else if myNewVal = "Opt 3" then
set newName to ((text item 1 of myFileName as string) & " - " & (text item 3 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 1 of myFileName as string)
end if
else
if myQuestion = "Yes" then
set newName to (text item 1 of myFileName as string) as string
tell this_track to set artist to newName
else
set newName to (((text item 2 of myFileName as string) as string) & " - " & (text item 1 of myFileName as string) as string) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 2 of myFileName as string)
end if
end if
end considering
else
set myFileName to (this_track's name) as Unicode text
considering case
set AppleScript's text item delimiters to "-"
if (count myFileName's text items) > 3 then
set myNewVal to button returned of (display dialog "Options:" & return & return & "1: " & ((text item 1 of myFileName as string) & " - " & (text item 2 of myFileName as string)) & return & "2: " & ((text item 2 of myFileName as string) & " - " & (text item 3 of myFileName as string)) & return & return buttons {"Opt 1", "Opt 2", "Next"} default button 2 with title my_title with icon caution)
if myNewVal = "Next" then
set myNewVal to button returned of (display dialog "Options:" & return & return & "1: " & ((text item 2 of myFileName as string) & " - " & (text item 3 of myFileName as string)) & return & "2: " & ((text item 3 of myFileName as string) & " - " & (text item 4 of myFileName as string)) & return & "3: " & ((text item 2 of myFileName as string) & " - " & (text item 4 of myFileName as string)) & return & return buttons {"Opt 1", "Opt 2", "Opt 3"} default button 1 with title my_title with icon caution)
if myNewVal = "Opt 1" then
set newName to ((text item 2 of myFileName as string) & " - " & (text item 3 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 2 of myFileName as string)
else if myNewVal = "Opt 2" then
set newName to ((text item 3 of myFileName as string) & " - " & (text item 4 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 3 of myFileName as string)
else if myNewVal = "Opt 3" then
set newName to ((text item 2 of myFileName as string) & " - " & (text item 4 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 2 of myFileName as string)
end if
else if myNewVal = "Opt 1" then
set newName to ((text item 1 of myFileName as string) & " - " & (text item 2 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 1 of myFileName as string)
else if myNewVal = "Opt 2" then
set newName to ((text item 2 of myFileName as string) & " - " & (text item 3 of myFileName as string)) as string
tell this_track to set name to newName
tell this_track to set artist to (text item 2 of myFileName as string)
end if
else if (count myFileName's text items) > 2 then
set myNewVal to button returned of (display dialog "Options:" & return & return & "1: " & ((this_track's artist) & " - " & (text item 1 of myFileName as string)) & return & "2: " & ((this_track's artist) & " - " & (text item 2 of myFileName as string)) & return & "3: " & ((this_track's artist) & " - " & (text item 3 of myFileName as string)) & return & return buttons {"Opt 1", "Opt 2", "Opt 3"} default button 1 with title my_title with icon caution)
if myNewVal = "Opt 1" then
set newName to ((this_track's artist) & " - " & (text item 1 of myFileName as string)) as string
tell this_track to set name to newName
else if myNewVal = "Opt 2" then
set newName to ((this_track's artist) & " - " & (text item 2 of myFileName as string)) as string
tell this_track to set name to newName
else if myNewVal = "Opt 3" then
set newName to ((this_track's artist) & " - " & (text item 3 of myFileName as string)) as string
tell this_track to set name to newName
end if
else
if myQuestion = "Yes" then
set newName to ((this_track's artist) & " - " & (text item 2 of myFileName as string) as string) as string
tell this_track to set name to newName
else
set newName to ((this_track's artist) & " - " & (text item 1 of myFileName as string) as string) as string
tell this_track to set name to newName
end if
end if
end considering
end if
else
if myQuestion = "Yes" then
set newName to ((this_track's artist) & " - " & (this_track's name)) as string
tell this_track to set name to newName
else
considering case
set AppleScript's text item delimiters to "-"
set myNewVal to button returned of (display dialog "Options:" & return & return & "1: " & ((this_track's artist) & " - " & (this_track's name)) & return & "2: " & ((this_track's name) & " - " & (this_track's artist)) & return & return buttons {"Opt 1", "Opt 2"} default button 2 with title my_title with icon caution)
if myNewVal = "Opt 1" then
set newName to ((this_track's artist) & " - " & (this_track's name)) as string
tell this_track to set name to newName
else if myNewVal = "Opt 2" then
set newName to ((this_track's name) & " - " & (this_track's artist)) as string
set newArtist to (this_track's name)
tell this_track to set name to newName
tell this_track to set artist to newArtist
end if
end considering
end if
end if
end if
end if
--the next few steps clean any funny characters and formatting
set thetxtfile to (this_track's name) as Unicode text
ignoring case
set thetxtfile to my findAndReplace("( ", "(", thetxtfile)
set thetxtfile to my findAndReplace(" )", ")", thetxtfile)
set thetxtfile to my findAndReplace("(", " (", thetxtfile)
set thetxtfile to my findAndReplace("[", " (", thetxtfile)
set thetxtfile to my findAndReplace("<", " (", thetxtfile)
set thetxtfile to my findAndReplace(">", " )", thetxtfile)
set thetxtfile to my findAndReplace("]", ")", thetxtfile)
set thetxtfile to my findAndReplace("_", " ", thetxtfile)
set thetxtfile to my findAndReplace(" -", "-", thetxtfile)
set thetxtfile to my findAndReplace("- ", "-", thetxtfile)
set thetxtfile to my findAndReplace("-", " - ", thetxtfile)
set thetxtfile to my findAndReplace("--", " - ", thetxtfile)
set thetxtfile to my findAndReplace(" &", "&", thetxtfile)
set thetxtfile to my findAndReplace("& ", "&", thetxtfile)
set thetxtfile to my findAndReplace("&", " & ", thetxtfile)
set thetxtfile to my findAndReplace(".mp3", "", thetxtfile)
set thetxtfile to my findAndReplace(".mp4", "", thetxtfile)
set thetxtfile to my findAndReplace(".wmv", "", thetxtfile)
set thetxtfile to my findAndReplace(".flv", "", thetxtfile)
set thetxtfile to my findAndReplace("Ft.", "feat.", thetxtfile)
set thetxtfile to my findAndReplace(" ", " ", thetxtfile)
set thetxtfile to my findAndReplace(" ", " ", thetxtfile)
set thetxtfile to my findAndReplace(" ", " ", thetxtfile)
set thetxtfile to my findAndReplace(" ", " ", thetxtfile)
set thetxtfile to my findAndReplace(" ", " ", thetxtfile)
end ignoring
tell this_track to set name to thetxtfile
set thetxtfile to (this_track's artist) as Unicode text
ignoring case
set thetxtfile to my findAndReplace("( ", "(", thetxtfile)
set thetxtfile to my findAndReplace(" )", ")", thetxtfile)
set thetxtfile to my findAndReplace("(", " (", thetxtfile)
set thetxtfile to my findAndReplace("[", " (", thetxtfile)
set thetxtfile to my findAndReplace("<", " (", thetxtfile)
set thetxtfile to my findAndReplace(">", " )", thetxtfile)
set thetxtfile to my findAndReplace("]", ")", thetxtfile)
set thetxtfile to my findAndReplace("_", " ", thetxtfile)
set thetxtfile to my findAndReplace(" -", "-", thetxtfile)
set thetxtfile to my findAndReplace("- ", "-", thetxtfile)
set thetxtfile to my findAndReplace("-", " - ", thetxtfile)
set thetxtfile to my findAndReplace("--", " - ", thetxtfile)
set thetxtfile to my findAndReplace(" &", "&", thetxtfile)
set thetxtfile to my findAndReplace("& ", "&", thetxtfile)
set thetxtfile to my findAndReplace("&", " & ", thetxtfile)
set thetxtfile to my findAndReplace(".mp3", "", thetxtfile)
set thetxtfile to my findAndReplace(".mp4", "", thetxtfile)
set thetxtfile to my findAndReplace(".wmv", "", thetxtfile)
set thetxtfile to my findAndReplace(".flv", "", thetxtfile)
set thetxtfile to my findAndReplace("Ft.", "feat.", thetxtfile)
set thetxtfile to my findAndReplace(" ", " ", thetxtfile)
set thetxtfile to my findAndReplace(" ", " ", thetxtfile)
set thetxtfile to my findAndReplace(" ", " ", thetxtfile)
set thetxtfile to my findAndReplace(" ", " ", thetxtfile)
set thetxtfile to my findAndReplace(" ", " ", thetxtfile)
end ignoring
tell this_track to set artist to thetxtfile
--remove spaces from front and back of name and artist
tell this_track to set name to my trim(this_track's name) as string
tell this_track to set artist to my trim(this_track's artist) as string
if pOldAlbumArtist = "" then set pOldAlbumArtist to (pFolder)
tell this_track to set album artist to (pFolder)
if pOldAlbum = "" then set pOldAlbum to (pList)
tell this_track to set album to (pList)
tell this_track to set genre to (pList) & " " & (pFolder)
tell this_track to set track count to ""
tell this_track to set track number to ""
tell this_track to set disc count to ""
tell this_track to set disc number to ""
tell this_track to set grouping to "DJ Jonny F"
tell this_track to set compilation to false
tell this_track to set comment to "A Track of " & (get album artist) & " nature, with a " & (get album) & " Mood setting. This was generated by a custom Tagger created by DJ Jonny-F (Jonathan Feeke - [email protected])"
end try
try
set getComposer to this_track's composer as string
if this_track's composer contains "Extra Info:" then
--do nothing, already exists
else
tell this_track to set composer to getComposer & ", Extra Info: " & pOldAlbum & " " & pOldAlbumArtist
end if
end try
if (count sel) = 1 then
if button returned of (display dialog "Get Artwork from Google?" & return & return buttons {"Yes", "No"} default button 2 with title my_title with icon 1 giving up after 30) is "Yes" then
--DOWNLOAD ARTWORK FROM GOOGLE (AMAZON) (ONLY IF 1 FILE IS SELECTED)
try
set the_name to (the name of this_track) as string
set the_artist to (the artist of this_track) as string
-- search for artist if no album name
if the_name is "" then
set this_searchstring to the_artist as string
else if the_artist is "" then
set this_searchstring to the_name as string
else
set this_searchstring to (the_artist & " AND " & the_name)
end if
on error error_message number error_number
if the error_number is not -128 then
beep
display dialog error_message buttons {"Cancel"} default button 1 with title my_title with icon 1 giving up after 30
else
error number -128
end if
end try
set the encoded_string to my urlencode(this_searchstring, false, false)
if limit_to_size is true and limit_to_domain is true then
set the final_url to (search_URL & encoded_string & "&as_sitesearch=" & search_domain & "&imgsz=" & image_size)
else if limit_to_size is true and limit_to_domain is false then
set the final_url to (search_URL & encoded_string & "&imgsz=" & image_size)
else if limit_to_size is false and limit_to_domain is true then
set the final_url to (search_URL & encoded_string & "&as_sitesearch=" & search_domain)
else
set the final_url to (search_URL & encoded_string)
end if
tell me to access_website(final_url)
end if
end if
--MODIFY CAPITILIZATION
set my_tags_to_modify to my_tags
repeat with selected_tag in my_tags_to_modify --Check which tags are to be modified.
set selected_tag to selected_tag as text
if selected_tag = "name" then set theTitle_as_List to (my text_to_list(this_track's name, space))
if selected_tag = "artist" then set theTitle_as_List to (my text_to_list(this_track's artist, space))
set newTitle to {}
set last_item to (count theTitle_as_List)
set word_counter to 1
repeat with editableText in theTitle_as_List
set replacementText to ""
repeat with my_unmodified_Match in unmodified_words
--Check if any of the words belong to the list of unmodified words.
if (my_unmodified_Match as text) = (editableText as text) then
set unmodified_Match to true
exit repeat
end if
end repeat
if unmodified_Match then
--Unmodify matching words in unmodified_words list (actually just copy the word from the list).
set replacementText to my_unmodified_Match as text
set unmodified_Match to false
else if (word_counter = 1) or (word_counter = last_item) then
--Capitalize first and last words in title.
my SetCase(editableText)
else
--For words not beginning or ending the title (middle words).
repeat with my_lowercase_Match in lowercase_words
--Check if any of the middle words belong to the list of lowerase words.
if (my_lowercase_Match as text) = (editableText as text) then
set lowercase_match to true
exit repeat
end if
end repeat
if lowercase_match then
--Lowercase matching words in lowercase_words list (actually just copy the word from the list).
set replacementText to my_lowercase_Match as text
set lowercase_match to false
else
--Capitalize the rest of the words.
my SetCase(editableText)
end if
end if
copy replacementText to end of newTitle
set word_counter to (word_counter + 1)
end repeat
-->> log (my list_to_text(newTitle, space)) -- de-bugging only
try
if selected_tag = "name" then set this_track's name to my list_to_text(newTitle, space)
if selected_tag = "artist" then set this_track's artist to my list_to_text(newTitle, space)
end try
end repeat
set iteration to (iteration + 1)
try
--EMBED ARTWORK
--added 19/07/2013
--set theData to data of artwork 1 of this_track
--set data of artwork 1 of this_track to (theData as picture)
repeat with anArtwork in artworks of this_track
if downloaded of anArtwork is true then
set theData to data of anArtwork
set data of anArtwork to theData
end if
end repeat
on error error_message number error_number
if the error_number is not -50 then
beep
display dialog error_message buttons {"Cancel"} default button 1 with title my_title with icon 1 giving up after 5
else
error number -50
end if
end try
end if
end repeat
end timeout
set fixed indexing to ofi
display dialog theUser & ", Final Clean is Complete!" & return & "Thanks for using this Script from Jonathan Feeke ([email protected])" & return buttons {"Ok"} default button 1 with icon 1 with title my_title giving up after 60
return
end if
end if
else
display dialog return & theUser & " ,Please Select Tracks within a Playlist first to use this Tool." buttons {"Ok"} default button 1 with icon 1 giving up after 30 with title my_title
return
end if
end if
end tell
--The handler taking care of the casing of words.
on SetCase(editableText)
repeat with j from 1 to (length of editableText)
if other_chars contains (character j of editableText) then
set j to (character j of editableText)
set replacementText to replacementText & j
set other_chars_match to true
else if other_chars_match then
set j to (character j of editableText)
if ((id of j) is greater than 96) and ((id of j) is less than 123) then
set replacementText to replacementText & (character id ((id of j) - 32))
else if ((id of j) is greater than 64) and ((id of j) is less than 91) then
set replacementText to replacementText & j
else
set replacementText to replacementText & j
end if
set other_chars_match to false
else if (j = 1) then
set j to (character j of editableText)
if ((id of j) is greater than 96) and ((id of j) is less than 123) then
set replacementText to replacementText & (character id ((id of j) - 32))
else
set replacementText to replacementText & j
end if
else
set j to (character j of editableText)
if ((id of j) is greater than 96) and ((id of j) is less than 123) then
set replacementText to replacementText & j
else if ((id of j) is greater than 64) and ((id of j) is less than 91) then
set x to (character id ((id of j) + 32))
set replacementText to replacementText & x
else
set replacementText to replacementText & j
end if
end if
end repeat
end SetCase
on text_to_list(txt, delim)
set saveD to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to {delim}
set theList to every text item of txt
on error errStr number errNum
set AppleScript's text item delimiters to saveD
error errStr number errNum
end try
set AppleScript's text item delimiters to saveD
return (theList)
end text_to_list
on list_to_text(theList, delim)
set saveD to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to {delim}
set txt to theList as text
on error errStr number errNum
set AppleScript's text item delimiters to saveD
error errStr number errNum
end try
set AppleScript's text item delimiters to saveD
return (txt)
end list_to_text
on findAndReplace(tofind, toreplace, TheString)
set ditd to text item delimiters
set text item delimiters to tofind
set textItems to text items of TheString
set text item delimiters to toreplace
if (class of TheString is string) then
set res to textItems as string
else -- if (class of TheString is Unicode text) then
set res to textItems as Unicode text
end if
set text item delimiters to ditd
return res
end findAndReplace
on trim(someText)
repeat until someText does not start with " "
set someText to text 2 thru -1 of someText
end repeat
repeat until someText does not end with " "
set someText to text 1 thru -2 of someText
end repeat
return someText
end trim
on urlencode(theText)
-- this routine from
-- http://harvey.nu/applescript_url_encode_routine.html
set theTextEnc to ""
repeat with eachChar in characters of theText
set useChar to eachChar
set eachCharNum to ASCII number of eachChar
if eachCharNum = 32 then
set useChar to "+"
else if (eachCharNum ≠ 42) and (eachCharNum ≠ 95) and (eachCharNum < 45 or eachCharNum > 46) and (eachCharNum < 48 or eachCharNum > 57) and (eachCharNum < 65 or eachCharNum > 90) and (eachCharNum < 97 or eachCharNum > 122) then
set firstDig to round (eachCharNum / 16) rounding down
set secondDig to eachCharNum mod 16
if firstDig > 9 then
set aNum to firstDig + 55
set firstDig to ASCII character aNum
end if
if secondDig > 9 then
set aNum to secondDig + 55
set secondDig to ASCII character aNum
end if
set numHex to ("%" & (firstDig as string) & (secondDig as string)) as string
set useChar to numHex
end if
set theTextEnc to theTextEnc & useChar as string
end repeat
return theTextEnc
end urlencode
on access_website(theURL)
try -- Jaguar default browser
tell application "Finder"
open location theURL
end tell
on error -- Panther and up default browser
tell application "System Events"
open location theURL
end tell
end try
end access_website
on display_progress(iteration, total_count, main_string, sub_string)
--choose from this list for the "unprocessed" part of the progress bar
set the_counter_opts to {" ", "▢▢▢▢▢▢▢▢▢▢▢▢▢▢▢", "▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣"}
set the_counter to (characters of (item 2 of the_counter_opts))
set the_percentage to (round of ((iteration / total_count) * (count of the_counter)) rounding up)
if the_percentage is not equal to 0 then
repeat with i from 1 to the_percentage
set item i of the_counter to "▣"
end repeat
end if
set the_counter to the_counter as string
set the_message to main_string & return & return & sub_string & return & return & the_counter
display dialog the_message buttons {"Cancel"} giving up after 1
end display_progress
to fix_filename(loc)
set finfo to (info for loc)
try
return text 1 thru -((length of (name extension of finfo)) + 2) of (displayed name of finfo)
on error -- no extension?
return (displayed name of finfo)
end try
end fix_filename
--ADD FILES TO ITUNES
on recurseDir(parent_folder, parent_ID, fileTypes)
log parent_folder
set item_list to ""
tell application "Finder"
try
set item_list to get the name of every item of parent_folder whose name extension is in fileTypes --{"mp3", "wav", "m4a"} --kind is "MPEG Audio Layer 3" or kind is "WAVE Audio File" or kind is "Apple MPEG-4 Audio"
set the_pList to get the displayed name of folder (parent_folder as alias) -- (info for parent_folder)
on error --no audio files
set item_list to {}
end try
end tell
set item_count to (get count of items in item_list)
tell application "iTunes"
try
if item_count > 0 then
set aPlaylist to (make playlist at (some folder playlist whose persistent ID is parent_ID) with properties {name:the_pList})
set thePlaylist to aPlaylist
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
add the_item to thePlaylist
set addedFiles to addedFiles + 1
my progressNotice()
end repeat
end if
end try
end tell
set item_list to ""
tell application "Finder"
try
set item_list to get the name of every item of parent_folder whose kind is "Folder"
on error --no more folders
set item_list to {}
end try
end tell
set item_count to (get count of items in item_list)
if item_count > 0 then
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
try
tell application "Finder"
--set file_info to get info for (the_item) -- as alias)
set new_playlist_name to get the displayed name of folder (the_item as alias) --(info for the_item as alias)
end tell
on error
tell application "Finder"
set new_playlist_name to (get the name of folder (the_item as alias))
end tell
end try
--set new_playlist_name to displayed name of file_info
--ADDED CODE
tell application "Finder"
try
set fol_list to get (the name of every item of the_item whose kind is "Folder")
on error
set fol_list to {}
end try
end tell
set fol_count to (get count of items in fol_list)
--END ADDED CODE
tell application "iTunes"
try
if fol_count > 0 then --ADDED CODE
set new_parent_ID to persistent ID of (make folder playlist at (some folder playlist whose persistent ID is parent_ID) with properties {name:new_playlist_name})
set addedFolders to addedFolders + 1
my progressNotice()
my recurseDir(the_item, new_parent_ID, fileTypes) --ADDED CODE
else --ADDED CODE
set item_listC to ""
tell application "Finder"
try
set item_listC to get (the name of every item of the_item whose name extension is in fileTypes) --{"mp3", "wav", "m4a"} --kind is "MPEG Audio Layer 3" or kind is "WAVE Audio File" or kind is "Apple MPEG-4 Audio"
set the_pListC to the displayed name of folder (the_item as alias) --(info for the_item)
on error --no audio files
set item_listC to {}
end try
end tell
set item_countC to (get count of items in item_listC)
tell application "iTunes"
try
if item_countC > 0 then
set aPlaylistC to (make playlist at (some folder playlist whose persistent ID is parent_ID) with properties {name:the_pListC})
set thePlaylistC to aPlaylistC
repeat with i from 1 to item_countC
set the_itemC to item i of the item_listC
set the_itemC to ((the_item & the_itemC) as string) as alias
add the_itemC to thePlaylistC
set addedFiles to addedFiles + 1
my progressNotice()
end repeat
end if
end try
end tell
end if --ADDED CODE
end try
end tell
--my recurseDir(the_item, new_parent_ID, fileTypes)
end repeat
end if
end recurseDir
on progressNotice()
if frontmost then
if (addedFiles mod 100) is 0 then
display dialog "Added/Edited " & addedFiles & " Tracks so far from " & addedFolders & " Folders" buttons {"Ok"} with icon 1 giving up after 5
end if
end if
end progressNotice
-- sub-routine to get individual names from the list, no dupes
to get_discrete_list_of(list1)
script a
property list1ref : list1
end script
set list2 to {}
script b
property list2ref : list2
end script
repeat with i from 1 to length of list1
set this_item to item i of a's list1ref
considering case
if this_item is not "" and this_item is not in b's list2ref then set end of list2 to this_item
end considering
end repeat
return b's list2ref
end get_discrete_list_of
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment