Folder Action Setup instead of Choose Folder

Hi:

Here I’ve a simple script to find file names with same name and group in new folder (folder name is same as file name):

My problems is that I used “on adding folder” and attached with folder but it does nothing.

Thank you!

property ff : {} -- list of aliases
property gg : {} -- list of aliases to be moved per prefix
property nn : {} -- list of file names
property mm : {} -- list of prefixes
property mm1 : {} -- list of distinct prefixes

on adding folder items to this_folder after receiving these_items
	tell application "Finder"
		tell item these_items to set {ff, nn} to {it as alias list, name}
	end tell
	
	try
		set {astid0, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {"_"}}
		repeat with i from 1 to count my nn
			set {n, m} to {my nn's item i, ""}
			if (count n's text items) > 1 then set m to "" & n's text items 1 thru -2
			set my mm's end to m
			if m ≠ "" and m is not in my mm1 then set my mm1's end to m
		end repeat
		set AppleScript's text item delimiters to astid0
	on error errs number errn
		set AppleScript's text item delimiters to astid0
		error errs number errn
	end try
	
	repeat with m in my mm1
		set m to m's contents
		try
			set dst to (d as string) & m & ":" as alias
		on error number -43 -- dst not present
			tell application "Finder" to set dst to (make new folder at d with properties {name:m}) as alias
		end try
		repeat with i from 1 to count my mm
			if my mm's item i = m then set my gg's end to my ff's item i
		end repeat
		if gg ≠ {} then tell application "Finder" to move gg to dst with replacing
		set gg to {}
	end repeat
end adding folder items to

Here is the tip which I use to test folder actions scripts.

(* There is no need to use properties here
property ff : {} -- list of aliases
property gg : {} -- list of aliases to be moved per prefix
property nn : {} -- list of file names
property mm : {} -- list of prefixes
property mm1 : {} -- list of distinct prefixes
*)
# Choose some files in the target folder
set these_items to choose file with multiple selections allowed

--on adding folder items to this_folder after receiving these_items

copy these_items to ff # The list is already an alias list
set nn to {}
tell application "Finder"
	set this_folder to container of ff's item 1 as alias
	log this_folder
	repeat with anAlias in ff
		set end of nn to name of anAlias
	end repeat
end tell
nn
#.

--end adding folder items to

As far I understand you are using a variable named d which is never defined.

Yvan KOENIG running El Capitan 10.11.5 in French (VALLAURIS, France) mercredi 8 juin 2016 17:31:53