I know that you guys are gonna start troll about me posting this, but I really need your help. I’ve been trying to figure out a way to do this, but no way to do it right now with my almost 0 knowledge about how to create my own scripts.
What I want to do is to use a script or automator to monitor my downloads folder (were I not only download MP3 files or audio files). Then I want it to move those audio files automatically to another folder. I want that to be an automatic process. So what I know is the following:
if (name extension =“mp3” or “m4a” or “m4b” or “aif” or “aiff” or “wav”) in folder /Users/Solly/Downloads then
mv /Solly/Downloads/files.whatever to /Users/Solly/Music/iTunes/iTunes Media/Automatically Add to iTunes
I know that the code is not going to work, but its a way to show you guys what I want to do.
So I already came up with a solution, the only problem is that it gives me an error that I don’t know how to solve
property extension_list : {"mp3", "m4a", "wav", "wma"}
tell application "Finder"
move {(every file of folder), "/Macintosh HD/Users/Solly/Downloads/" whose name extension is in extension_list} to folder "/Macintosh HD/Users/Solly/Music/iTunes/iTunes Media/Automatically Add to iTunes"
end tell
error:
error "Can't get every file of folder." number -1728 from every file of «class cfol»
Try adding this as a folder action to your downloads folder:
property extension_list : {"mp3", "m4a", "wav", "wma"}
property destFolder : alias "Macintosh HD:Users:Solly:Music:iTunes:iTunes Media:Automatically Add to iTunes:"
on adding folder items to theFolder after receiving theFiles
repeat with aFile in theFiles
tell (info for aFile)
if name extension is in extension_list then
tell application "Finder" to move aFile to destFolder
end if
end tell
end repeat
end adding folder items to
Finder does not understand POSIX (slash-delimited) paths, it uses HFS (colon-delimited) paths only.
Info for is deprecated, meaning it will cease to work without warning. Finder also knows about name extension, so this works:
repeat with aFile in theFiles
tell application "Finder"
if name extension is in extension_list then
move aFile to destFolder
end if
end tell
end repeat
Some boot disks are not called ‘Macintosh HD’:
property destFolder : alias "Macintosh HD:Users:Solly:Music:iTunes:iTunes Media:Automatically Add to iTunes:"
This will make it drive-agnostic:
property partialPath : "Music:iTunes:iTunes Media:Automatically Add to iTunes:"
tell application "Finder"
set destFolder to folder partialPath of home
end tell
Be aware that iTunes’ folder structure has changed over the years, and the ‘Media’ folder may be ‘Music’ instead. Also, some folders have localised names.
Perfect! This is exactly what I needed. I don’t know why the alias isn’t working, so I removed that line and changed the destFolder alias to the complete path and now it works!
property extension_list : {"mp3", "m4a", "wav", "wma"}
on adding folder items to theFolder after receiving theFiles
repeat with aFile in theFiles
tell (info for aFile)
if name extension is in extension_list then
tell application "Finder" to move aFile to "Macintosh HD:Users:Solly:Music:iTunes:iTunes Media:Automatically Add to iTunes:"
end if
end tell
end repeat
end adding folder items to
Another approach is to add the file(s) directly in iTunes
property extensionList : {"mp3", "aif", "wav", "m4a", "m4b"}
property deleteFileAfterAddingToItunes : false
on adding folder items to theFolder after receiving theFiles
set iTunesIsRunning to application "iTunes" is running -- check if iTunes is currently running
set iTunesLaunched to false
repeat with aFile in theFiles
if iTunesLaunched is false and iTunesIsRunning is false then
launch application "iTunes"
set iTunesLaunched to true
end if
tell application "System Events" to set isValidMusicFile to name extension of aFile is in extensionList
if isValidMusicFile then
tell application "iTunes" to add aFile to library playlist 1
if deleteFileAfterAddingToItunes then tell application "Finder" to delete aFile
end if
end repeat
if not iTunesIsRunning then quit application "iTunes"
end adding folder items to