Need script to change label of folder to match qty of contents

Just starting to work, a little, with automator, but applescript is an unknown to me. I see a number of scripts that change labels of items dropped on a folder, but not changing the folder itself. Can this be done?

I need a folder action script that changes the label of the folder it is attached to, (not the items dropped in/taken out), to indicate on any change to the folder how many items are in it ie 1 thru 7 (and more than 7 would equal 7 I guess - and preferences could be changed to indicate under the name how many items anyway).

Kind of like a mail box flag to indicate something is in it. When emptied, it goes back to none. Across a network, adding newly created files to someone elses “in tray” folder this would visibly tell them something new has been added.

TIA. :slight_smile:

Model: g5 dual 2
AppleScript: ?? script editor 2.1
Browser: Safari 412.2.2
Operating System: Mac OS X (10.4)

That’s an interesting use of folder actions.

Try this:

-- You can change the order of these items. The first item means no items, and the last item means seven or more items. Make sure the last item doesn't have a comma.
property labels : {¬
	{name:"(None)", index:0}, ¬
	{name:"Grey", index:7}, ¬
	{name:"Purple", index:5}, ¬
	{name:"Blue", index:4}, ¬
	{name:"Green", index:6}, ¬
	{name:"Yellow", index:3}, ¬
	{name:"Orange", index:1}, ¬
	{name:"Red", index:2} ¬
		}

on adding folder items to thisFolder after receiving addedItems
	changeLabel(thisFolder)
end adding folder items to

on removing folder items from thisFolder after losing removedItems
	changeLabel(thisFolder)
end removing folder items from

on changeLabel(theFolder)
	try
		list folder theFolder without invisibles
		
		set theCount to (count result) + 1
		if theCount > 8 then set theCount to 8
		
		tell application "Finder"
			launch
			set label index of theFolder to (index of (item theCount of labels))
		end tell
	on error errorMsg number errorNum
		display dialog "Error (" & errorNum & "):" & return & return & errorMsg buttons "Cancel" default button 1 with icon caution
	end try
end changeLabel

:smiley: Woah, thanks Bruce. haven’t tried yet, but looks exactly the solution…

one more interesting, maybe:

Will this work (how setup?) on a .Mac iDisk? Who enables folder actions, the owner/user? Does that make sense? I drop items into a folder on someone elses iDisk and this script does it’s thing. … Can you switch on folder actions on an iDisk, where does the script app reside for it to be called on?

Your post made me think about this not as fancy as Bruce but here it is anyway

on adding folder items to thisFolder after receiving addedItems
	tell application "Finder"
		set myfolder to folder thisFolder
		set disname to displayed name of myfolder
		set fcount to count of every file of myfolder
		set fcount1 to count of every folder of myfolder
		set newname to ("fringe " & (fcount1 as string) & "folders" & " " & (fcount as string) & "files")
		set name of myfolder to newname
	end tell
end adding folder items to

on removing folder items from thisFolder after losing removedItems
	tell application "Finder"
		set myfolder to folder thisFolder
		set disname to displayed name of myfolder
		set fcount to count of every file of myfolder
		set fcount1 to count of every folder of myfolder
		set newname to ("fringe " & (fcount1 as string) & "folders" & " " & (fcount as string) & "files")
		set name of myfolder to newname
	end tell
end removing folder items from

You could reduce the code by removing the duplication but it works.

I’ll test this as soon as I can.