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


Click here to return to the 'No need to store name in Finder Comment' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
No need to store name in Finder Comment
Authored by: Krioni on Apr 10, '06 02:32:30PM
Here's a modified version of the script that extracts the base name of the folder (everything before the last open parenthesis). Also, you could change the delimiters that surround the number to something else by just changing the first two lines of the script. Here it is:

property countStart : space & "("
property countEnd : ")"


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 oldName to name of theFolder
		
		set myCount to the count of (every item of theFolder)
		if myCount > 0 then set nameEnd to " (" & myCount & ")"

	-- here is where Dan Shockley (Krioni) removed need to store folder name in Finder Comment:
		
		if oldName contains countStart and oldName contains countEnd then
			set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, countStart}
			set nameBase to items 1 through -2 of (text items of oldName)
			set nameBase to nameBase as string
			set AppleScript's text item delimiters to od
			set newName to nameBase & countStart & myCount & countEnd
		else -- no previous count to replace
			set newName to oldName & countStart & myCount & countEnd
		end if
		
		set name of theFolder to newName
		
	end tell
end setTheCount


[ Reply to This | # ]
No need to store name in Finder Comment
Authored by: lifeclever on Jul 25, '06 10:45:49AM

This revision to the code is great and makes it a lot easier to setup. Is there a way in AppleScript to find all the aliases of a folder and rename them with the item count to match the original folder as well?

---
http://www.lifeclever.com
Tips for design and life



[ Reply to This | # ]