First version using the Finder.
property movieFiles : {"mov", "m4v", "mkv", "avi", "mp4"} # I added mp4
property musicFiles : {"mp3"}
(*
# Instructions used for testing
set theFolder to ((path to desktop as text) & "receiver:") as alias
tell application "Finder" to set thefiles to files of theFolder as alias list
*)
on adding folder items to theFolder after receiving thefiles
set baseFolder to "My Book for Mac:Torrent Downloads:"
# Here is the storage folder used in my tests
set baseFolder to (path to desktop as text) & "final storage:Torrent Downloads:"
repeat with aFile in thefiles
tell application "Finder"
set nameExt to name extension of aFile
if nameExt is in movieFiles then
duplicate aFile to the folder (baseFolder & "Movies")
else if nameExt is in musicFiles then
duplicate aFile to the folder (baseFolder & "Music")
end if
end tell
end repeat
end adding folder items to
It works but it’s awfully slow - not a surprise.
The original files remain in theFolder
Second version using System Events
property movieFiles : {"mov", "m4v", "mkv", "avi", "mp4"} # I added mp4
property musicFiles : {"mp3"}
(*
# Instructions used for testing
set theFolder to ((path to desktop as text) & "receiver:") as alias
tell application "Finder" to set thefiles to files of theFolder as alias list
*)
on adding folder items to theFolder after receiving thefiles
set baseFolder to "My Book for Mac:Torrent Downloads:"
# Here is the storage folder used in my tests
set baseFolder to (path to desktop as text) & "final storage:Torrent Downloads:"
repeat with aFile in thefiles
tell application "System Events"
set nameExt to name extension of aFile
if nameExt is in movieFiles then
move aFile to the folder (baseFolder & "Movies")
else if nameExt is in musicFiles then
move aFile to the folder (baseFolder & "Music")
end if
end tell
end repeat
end adding folder items to
It works, it’s fast but the originals are no longer in theFolder.
I was unable to use the duplicate command available in System Events.
Third version using the shell command mv.
property movieFiles : {"mov", "m4v", "mkv", "avi", "mp4"} # I added mp4
property musicFiles : {"mp3"}
(*
# Instructions used for testing
set theFolder to ((path to desktop as text) & "receiver:") as alias
tell application "Finder" to set thefiles to files of theFolder as alias list
*)
on adding folder items to theFolder after receiving theFiles
set baseFolder to "My Book for Mac:Torrent Downloads:"
# Here is the storage folder used in my tests
set baseFolder to (path to desktop as text) & "final storage:Torrent Downloads:"
repeat with aFile in theFiles
tell application "System Events"
set nameExt to name extension of aFile
end tell
if nameExt is in movieFiles then
--display dialog "It recognised the movie"
do shell script "mv " & quoted form of POSIX path of aFile & " " & quoted form of POSIX path of (baseFolder & "Movies")
else if nameExt is in musicFiles then
do shell script "mv " & quoted form of POSIX path of aFile & " " & quoted form of POSIX path of (baseFolder & "Music")
end if
end repeat
end adding folder items to
It works, it’s faster but as in second version the original files are no longer in theFolder.
If you want to keep the originals in theFolder, replace
do shell script "mv "
by
do shell script "cp "
It’s not so fast than cp but it’s faster than the Finder version.
Yvan KOENIG running El Capitan 10.11.3 in French (VALLAURIS, France) mardi 26 janvier 2016 19:00:27