Clean FolderAction List

When you often delete folder with actions attached, folder action setup keeps them in the list…
So I’ve wrote a script which checks every folder in the list. If it no longer existor it’s in the trash, it will be removes from list.

Here’s the code:


property NoFoldersActionsExist : "There are no folder actions."

tell application "System Events"
	set FoldersWithActions to path of every folder action
	set FolderActionNames to name of every folder action as list
end tell

if FoldersWithActions is {} then
	activate
	display dialog NoFoldersActionsExist with icon note
else
	set vHaveTrashed to false
	set vTrashedFolders to 0
	repeat with i from 1 to (count items of FoldersWithActions)
		try
			tell application "Finder"
				get folder (item i of FoldersWithActions)
			end tell
			if (item i of FoldersWithActions as string) contains "trash" then
				set vChoice to button returned of ¬
					(display dialog "Folder \"" & (item i of FolderActionNames) & "\" is in the trash." & return & "Shall I remove its folderactions?" buttons {"No", "Yes"} default button 2 with icon 2)
				if vChoice is "Yes" then
					tell application "System Events" to delete folder action (item i of FolderActionNames)
					set vHaveTrashed to true
					set vTrashedFolders to vTrashedFolders + 1
				end if
			end if
			--(*
		on error
			set vChoice to button returned of (display dialog "Can't find folder: \"" & (item i of FolderActionNames) & "\"" & return & "Shall I remove this folder from the folderactionlist?" buttons {"Cancel", "OK"} default button 2 with icon 2)
			if vChoice is "OK" then
				tell application "System Events" to delete folder action (item i of FolderActionNames)
				set vHaveTrashed to true
				set vTrashedFolders to vTrashedFolders + 1
			end if --*)
		end try
	end repeat
	if vHaveTrashed is false then
		display dialog "All Folder Actions still exist." & return & "No Folder Actions trashed." buttons {"OK"} default button 1 with icon 1
	else
		display dialog "Succesfully trashed " & vTrashedFolders & " non existing folders." buttons {"OK"} default button 1 with icon 1
	end if
end if

Or download the Application with icons overhere.

Useful script.

But here the author has a lot of confused or excessive. So I tried to put things in their places. In addition, I wanted the script to return as result the list of valid hot folders. It seems, works fine:


set removedFoldersActions to 0

tell application "System Events"
	-- GET LIST OF FOLDER ACTIONS FOLDERS (that is, hot folders list)
	set hotFolders to every folder action
	-- RETURN, IF NO FOUNDED FOLDER ACTIONS FOLDERS (HOT FOLDERS)
	if hotFolders = {} then
		display dialog "THERE ARE NO HOT FOLDERS ON MAC." with icon note giving up after 5
		return
	end if
	
	-- LOOP FOLDER ACTIONS
	repeat with hotFolder in hotFolders
		
		-- IF NO ANY SCRIPT,  ATTACHED & ENABLED  FOUNDED FOR THIS HOT FOLDER....
		if (every script of hotFolder whose enabled is true) = {} then
			
			display dialog "THE ARE NO ACTIONS, ATTACHED TO HOT FOLDER \"" & (name of hotFolder) ¬
				& "\"" & return & return & "REMOVE ITS  FOLDER ACTIONS FUNCTIONALITY ?" buttons {"YES", "NO"} ¬
				default button "YES" with icon 2
			if (button returned of result) is "YES" then
				tell application "System Events" to delete hotFolder -- delete folder action (hot folder)
				set removedFoldersActions to removedFoldersActions + 1
			end if
			-- MAY BE YOU HAVE HOT FOLDER MOVED TO THE TRASH...	
		else if (path of hotFolder contains "trash") then
			
			display dialog "HOT FOLDER \"" & (name of hotFolder) & "\" IS IN THE TRASH." & return & return & ¬
				"REMOVE ITS  FOLDER ACTIONS FUNCTIONALITY ?" buttons {"YES", "NO"} default button "YES" with icon 2
			if (button returned of result) is "YES" then
				tell application "System Events" to delete hotFolder -- delete folder action (hot folder)
				set removedFoldersActions to removedFoldersActions + 1
			end if
			
		end if
		
	end repeat
end tell

tell me to activate
if removedFoldersActions = 0 then
	display dialog "All Folder Actions Folders on Mac was valid." & return & return & ¬
		"No Folder Actions Deleted Now." buttons {"OK"} default button 1 with icon 1
else
	display dialog "Succesfully Deleted " & removedFoldersActions & ¬
		" invalid Folder Actions." buttons {"OK"} default button 1 with icon 1
end if

return hotFolders -- remained (valid) Folder Actions Folders list of your Mac