hi,
im trying to compile a script that clears all files and folders from my desktop and then creates and moves the item to a “stray files” folder on the desktop and organizes them by name extention.
so far i have a working script that does all of the above, but if the stray files folder is removed, it no loger works.
so i decided to get round this by creating a folder action for the desktop so that if a new stray files folder is added to the destop it assignes a new folder action consisting of the above, this also works so far.
however for this to work completely i also need to create a FA script that removes the above FA script so that it can be carried out again,
i have been trying to reverse the process of the add FA script, but i can’t quite get it.
maybe someone here can see where i’m going wrong.
here is the add FA script:
on adding folder items to this_folder after receiving added_items
repeat with this_item in added_items
set temp to (contents of this_item)
tell application "Finder"
if kind of temp is "Folder" then
if name of temp is "stray files" then
my attachFA(temp, "close.scpt")
end if
end if
end tell
end repeat
set fp to quoted form of POSIX path of this_folder
try
tell application "Finder"
activate
set a to theFolder
set file_groups to {{"PD's", "pd"}, {"Torrents", ".torrent"}, {"Logic songs", "lso"}, {"Audio", "wav"}, {"Audio", "aif"}, {"Audio", "aiff"}, {"Audio", "mp3"}, {"Audio", "rex"}, {"Audio", "m4a"}, {"QuickTime", "mpe"}, {"QuickTime", "mpg"}, {"QuickTime", "mpeg"}, {"QuickTime", "mov"}, {"QuickTime", "avi"}, {"QuickTime", "3gp"}, {"Images", "jpg"}, {"Images", "gif"}, {"Images", "psd"}, {"Images", "tif"}, {"Images", "pic"}, {"Images", "jpeg"}, {"Images", "png"}, {"Windows Media", "wmv"}, {"Windows Media", "asf"}, {"RealPlayer", "ram"}, {"RealPlayer", "rm"}, {"Documents", "txt"}, {"Documents", "doc"}, {"Documents", "word doc"}, {"Pdf's", "pdf"}, {"Documents", "rtf"}, {"Documents", "rtf"}, {"Documents", "txt"}, {"Documents", "css"}, {"Documents", "text"}, {"Documents", "htm"}, {"Documents", "html"}, {"Pc", "exe"}, {"Download's", "download"}, {"App,s", "app"}, {"Mac", "dmg"}, {"Script's", "scpt"}, {"Workflows's", "workflow"}, {"Midi", "mid"}, {"Rex", "rx2"}, {"Flash", "swf"}, {"Flash", "flp"}, {"Flash", "fla"}, {"Pref's", "plist"}, {"Archives", "sitx"}, {"Archives", "tar"}, {"Archives", "sit"}, {"Archives", "rar"}, {"Archives", "zip"}, {"Waveburner", "wb3"}}
set the folder_name to {}
set the file_type to {}
set the chosen_folder to a
repeat with i from 1 to the count of the file_groups
copy item i of the file_groups to {folder_name, file_type}
set selected_files to (every file of chosen_folder whose name extension contains file_type)
if selected_files is not equal to {} then
if not (exists folder folder_name of folder chosen_folder) then
make new folder at folder chosen_folder with properties {name:folder_name}
end if
end if
select (every item of chosen_folder whose name extension contains file_type)
try
move the selection to folder folder_name of folder chosen_folder with replacing
end try
end repeat
end tell
end try
end adding folder items to
on attachFA(currFolder, ScriptName)
tell application "Finder" to set FAName to name of currFolder
tell application "System Events"
if not (exists folder action FAName) then
make new folder action at end of folder actions with properties {path:currFolder}
end if
if (get name of every script of folder action FAName) does not contain ScriptName then
tell folder action FAName to make new script at end of scripts with properties {name:ScriptName}
end if
end tell
end attachFA
and here is the remove FA script:
on removing folder items from this_folder after losing these_items
repeat with this_item in these_items
set temp to (contents of this_item)
tell application "Finder"
if kind of temp is "Folder" then
if name of temp is "stray files" then
my removeFA(temp, "close.scpt")
end if
end if
end tell
end repeat
set fp to quoted form of POSIX path of this_folder
end removing folder items from
on removeFA(currFolder, ScriptName)
tell application "Finder" to set FAName to name of currFolder
tell application "System Events"
if (exists folder action "stray files") then
delete (folder action whose name is "stray files")
end if
end tell
end removeFA
good luck and thanks in advance.
peace,
truth