Hello, I’m writing an Applescript that moves files based on their extension. However, I’m having several problems with it. First, I am trying to make a duplicate file handler and I’m not sure how to implement it. Second, I’m curious if I can make a file for the AppleScript access which contains the path to the download folder which it is to organize even after closing. Finally, can I add functionality for folders?
Thanks!
--Properties, adjust to your own specifications.
property graphicExtList : {"jpeg", "jpg", "gif", "psd", "png"}
property movieExtList : {"mov", "mpg", "mp4"}
property filesExtList : {"zip", "dmg", "exe", "pkg", "docx", "jar"}
property appExtList : {"app"}
property bookExtList : {"epub", "mobi"}
property musicExtList : {"mp3", "m4a", "ALAC"}
# I'll add more formats later on and add the ability to modify them and where they're moved.
set base to choose folder with prompt "Select the folder you'd like to organize."
set f1 to (base & "Files") as text
set f2 to (base & "Pics") as text
set f3 to (base & "Videos") as text
set f4 to (base & "Misc") as text
set f5 to (base & "Books") as text
set listOfNames to {}
set uname to system attribute "USER"
tell application "Finder"
if not (exists folder f1) then ¬
make new folder at base with properties {name:"Files"}
if not (exists folder f2) then ¬
make new folder at base with properties {name:"Pics"}
if not (exists folder f3) then ¬
make new folder at base with properties {name:"Videos"}
if not (exists folder f4) then ¬
make new folder at base with properties {name:"Misc"}
if not (exists folder f5) then ¬
make new folder at base with properties {name:"Books"}
end tell
tell application "Finder"
set filelist to every file of the base
repeat with currentFile in filelist
if name extension of currentFile is in the filesExtList then
move currentFile to f1
else if name extension of currentFile is in the graphicExtList then
move currentFile to f2
else if name extension of currentFile is in the appExtList then
move currentFile to f3
else if name extension of currentFile is in the bookExtList then
move currentFile to f4
else
move currentFile to f5
end if
end repeat
end tell