Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Display folder item counts via folder action script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Display folder item counts via folder action script
Authored by: diamondsw on Apr 07, '06 10:13:49AM

Hold it - what's with the dependency on "comment of theFolder"? Seems like you have to store the name of the folder in the comment ahead of time. A more robust solution would find if there is already a count attached and if necessary remove it, then add the new count.



[ Reply to This | # ]
Display folder item counts via folder action script
Authored by: tmm8a on Apr 07, '06 02:14:39PM
I fixed the need to put the name in the comment with a simple addition to the script. It looks at the comment and if it is blank copies in the name. This makes sure you never lose the folder name.

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

on removing folder items from thisFolder after losing addedItems
	my setTheCount(thisFolder)
end removing folder items from

on setTheCount(theFolderAlias)
	tell application "Finder"
		set theFolder to (folder theFolderAlias)
		set myCount to the count of (every item of theFolder)
		if comment of theFolder = "" then
			set comment of theFolder to name of theFolder
		end if
		set nameEnd to ""
		if myCount > 0 then set nameEnd to " (" & myCount & ")"
		set name of theFolder to (comment of theFolder) & nameEnd
	end tell
end setTheCount
I played around with trying to strip the "(xx)" at the end of the name string but it seemed to break the script. This is my first look into Applescript so I'm sure it is quite easy to play around with strings but I just couldn't figure it out. I also don't know how to step through a script and see what values the variables have. If I could do this than I would have some idea where the script was failing. It did fail gracefully in that it just did nothing.

[ Reply to This | # ]