Need help with folder action script to auto sort filetypes

For startes I’d like to say hello to everyone! I’m new to applescripting, but am trying to learn. I made this script from some others so that whenever I drop a bunch of Gradients, Brushes, etc. onto the Photoshop Presets folder, it will auto sort the files without me having to go to each folder. The only problem is that I can’t get that dialog box to do what I want.

Currently, it will show a dialog after each one that says “Auto sorted a (whatever)” I would like it to display one dialog after it autosorts ALL of the items, and offers a summary; like "Autosorted 3 Brushes, 2 Gradients, etc. and has an OK button. Can anyone help me out? My goal is to then release this so everyone can use it; as I think it would be pretty useful.

Thanks to anyone that can help!


--This Folder Action should be attached to the Photoshop:Presets folder. Just drop the new files onto the Presets folder, and they will be auto sorted into their correct folders.--

property BrushesRecord : {extension:"abr", description:"Brushes", directory:"Brushes"}
property ColorSwatchesRecord : {extension:"aco", description:"Color Swatches", directory:"Color Swatches"}
property ContourRecord : {extension:"sch", description:"Contours", directory:"Contours"}
property ShapesRecord : {extension:"csh", description:"Custom Shapes", directory:"Custom Shapes"}
property GradientRecord : {extension:"grd", description:"Gradients", directory:"Gradients"}
property PatternRecord : {extension:"pat", description:"Patterns", directory:"Patterns"}
property ActionsRecord : {extension:"atn", description:"Actions", directory:"Photoshop Actions"}
property StyleRecord : {extension:"asl", description:"Styles", directory:"Styles"}

property validRecords : {BrushesRecord, ColorSwatchesRecord, ContourRecord, ShapesRecord, GradientRecord, PatternRecord, ActionsRecord, StyleRecord}

--The handler for responding to when items are added to a folder: 

on adding folder items to TargetFolder after receiving DroppedItems
	
	--	set targetFolderAlias to targetFolder as alias
	repeat with currentFile in DroppedItems
		
		tell application "Finder"
			set targetFolderName to the name of TargetFolder
			set droppedFileName to the name of currentFile
			set droppedFileInfo to info for currentFile
		end tell
		
		repeat with currentRecord in validRecords
			if extension of currentRecord is equal to the name extension of droppedFileInfo then
				
				tell application "Finder"
					set newTargetFolder to (folder named (directory of currentRecord) of TargetFolder)
					if newTargetFolder exists then -- not sure about validity of this line...
						move currentFile to newTargetFolder
						display dialog " " & targetFolderName & " has auto-sorted a " & description of currentRecord & "." buttons {"OK"} default button 1 giving up after 2 --seconds
					else
						display dialog "the folder isn't there!" buttons {"OK"}
					end if
				end tell
				
			end if
		end repeat
		
	end repeat
end adding folder items to

Hi,

if you want to display a summary at the end you have to insert a display dialog after the repeat statement and make a kind of counter that adds up when items are moved. I quickly made some adjustments to count the number of action that have been moved. I haven’t been able to test it but it should help you. If you still have problems or something isn’t clear (i’ve added comments) let me know, i’ll try and fix it tonight at home… good luck

Here’s the code

property BrushesRecord : {extension:“abr”, description:“Brushes”, directory:“Brushes”}
property ColorSwatchesRecord : {extension:“aco”, description:“Color Swatches”, directory:“Color Swatches”}
property ContourRecord : {extension:“sch”, description:“Contours”, directory:“Contours”}
property ShapesRecord : {extension:“csh”, description:“Custom Shapes”, directory:“Custom Shapes”}
property GradientRecord : {extension:“grd”, description:“Gradients”, directory:“Gradients”}
property PatternRecord : {extension:“pat”, description:“Patterns”, directory:“Patterns”}
property ActionsRecord : {extension:“atn”, description:“Actions”, directory:“Photoshop Actions”}
property StyleRecord : {extension:“asl”, description:“Styles”, directory:“Styles”}

property validRecords : {BrushesRecord, ColorSwatchesRecord, ContourRecord, ShapesRecord, GradientRecord, PatternRecord, ActionsRecord, StyleRecord}

property action_count : 0
–The handler for responding to when items are added to a folder:

on adding folder items to TargetFolder after receiving DroppedItems
– because action_count is a property and therefore saved has to be reset to 0
tell application “Finder”
set action_count to 0
end tell
– set targetFolderAlias to targetFolder as alias
repeat with currentFile in DroppedItems
tell application “Finder”
set targetFolderName to the name of TargetFolder
set droppedFileName to the name of currentFile
set droppedFileInfo to info for currentFile

		repeat with currentRecord in validRecords
			if extension of currentRecord is equal to the name extension of droppedFileInfo then
				tell application "Finder"
					set newTargetFolder to (folder named (directory of currentRecord) of TargetFolder)
					if newTargetFolder exists then -- not sure about validity of this line... 
						move currentFile to newTargetFolder
						
						--add to counter if an action has been moved
						if extension of currentRecord = "grd" then
							set action_count to action_count + 1
						end if
						
					else
						display dialog "the folder isn't there!" buttons {"OK"}
					end if
				end tell
				
			end if
		end repeat
	end tell
end repeat

-- display the number of items an action has been moved
display dialog "number of actions" & action_count

end adding folder items to

Here’s my feeble, untested attempt at it.

 property BrushesRecord : {extension:"abr", description:"Brushes", directory:"Brushes", count_:0, record_name:"Brushes"}
 property ColorSwatchesRecord : {extension:"aco", description:"Color Swatches", directory:"Color Swatches", count_:0, record_name:"Color Swatches"}
 property ContourRecord : {extension:"sch", description:"Contours", directory:"Contours", count_:0, record_name:"Contours"}
 property ShapesRecord : {extension:"csh", description:"Custom Shapes", directory:"Custom Shapes", count_:0, record_name:"Shapes"}
 property GradientRecord : {extension:"grd", description:"Gradients", directory:"Gradients", count_:0, record_name:"Gradients"}
 property PatternRecord : {extension:"pat", description:"Patterns", directory:"Patterns", count_:0, record_name:"Patterns"}
 property ActionsRecord : {extension:"atn", description:"Actions", directory:"Photoshop Actions", count_:0, record_name:"Actions"}
 property StyleRecord : {extension:"asl", description:"Styles", directory:"Styles", count_:0, record_name:"Styles"}

 property validRecords : {BrushesRecord, ColorSwatchesRecord, ContourRecord, ShapesRecord, GradientRecord, PatternRecord, ActionsRecord, StyleRecord}

 --The handler for responding to when items are added to a folder: 
 on adding folder items to TargetFolder after receiving DroppedItems
  
  --   set targetFolderAlias to targetFolder as alias 
  repeat with currentFile in DroppedItems
   
   tell application "Finder"
    set targetFolderName to the name of TargetFolder
    set droppedFileName to the name of currentFile
    set droppedFileInfo to info for currentFile
   end tell
   
   repeat with currentRecord in validRecords
    if extension of currentRecord is equal to the name extension of droppedFileInfo then
     set (count_ of currentRecord) to ((count_ of currentRecord) + 1)
     tell application "Finder"
      set newTargetFolder to (folder named (directory of currentRecord) of TargetFolder)
      if newTargetFolder exists then -- not sure about validity of this line... 
       move currentFile to newTargetFolder
       display dialog " " & targetFolderName & " has auto-sorted a " & description of currentRecord & "." buttons {"OK"} default button 1 giving up after 2 --seconds 
      else
       display dialog "the folder isn't there!" buttons {"OK"}
      end if
     end tell
     exit repeat
    end if
   end repeat
  end repeat
  
  -- build the text for the summary dialog
  set finalDialog to "Autosorted "
  repeat with currentRecord in validRecords
   if count_ of currentRecord is not 0 then
    set finalDialog to finalDialog & "" & (count_ of currentRecord) & " " & (name_ of currentRecord) & ", "
   end if
  end repeat
  
  set finalDialog to text 1 thru -3 of finalDialog -- remove the trailing comma and space from the final output
  display dialog finalDialog
  
  -- reset the counts to 0
  repeat with currentRecord in validRecords
   set count_ of currentRecord to 0
  end repeat
 end adding folder items to

– Rob