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

Automatically attach color labels to files System
If you save the following AppleScript into /Library » Scripts » Folder Action Scripts, and set it up as a folder action, it will automatically color-label any file that you drop into the folder. I use it on my desktop to automatically color code anything that I download. Here's how to use it:
  1. Copy this code snippet into Script Editor:

    on adding folder items to this_folder after receiving these_items
      set fileColorList to {oranges:{"mpg", "mpeg", "bmp", "wma", "c", "cpp", "dmg", "doc"}, reds:{"asf", "jpg", "jpeg", "ram", "h", "hpp", "mpkg", "iso", "bin", "ppt", "pps"}, yellows:{"mov", "qt", "gif", "aif", "aiff", "htm", "html", "hqx", "tar", "xls"}, greens:{"mp4", "rgb", "rgba", "pcm", "js", "css", "cgi", "pkg", "gz", "z", "tgz", "pdf"}, blues:{"avi", "tif", "tiff", "mp3", "m", "zip", "eps", "ai"}, purples:{"wmv", "png", "wav", "scpt", "tbz", "bz2", "dat", "txt", "prefs"}, greys:{"rm", "ram", "ra", "psd", "pl", "xml", "plist", "sit", "rar", "rtf", "rtfd", "torrent"}}
      
      tell application "Finder"
        
        repeat with myFile in these_items
          --display dialog myFile as string
          if the name extension of myFile is in oranges of fileColorList then
            set label index of myFile to 1
          else if the name extension of myFile is in reds of fileColorList then
            set label index of myFile to 2
          else if the name extension of myFile is in yellows of fileColorList then
            set label index of myFile to 3
          else if the name extension of myFile is in blues of fileColorList then
            set label index of myFile to 4
          else if the name extension of myFile is in purples of fileColorList then
            set label index of myFile to 5
          else if the name extension of myFile is in greens of fileColorList then
            set label index of myFile to 6
          else if the name extension of myFile is in greys of fileColorList then
            set label index of myFile to 7
          end if
          
        end repeat
      end tell
    end adding folder items to
  2. Save the script into /Library » Scripts » Folder Action Scripts.
  3. Control-click on the Desktop and select Enable Folder Actions from the pop-up menu.
  4. Control-click on the desktop and select Configure Folder Actions from the pop-up menu.
  5. Select the script that you just saved from the list.
Voila -- anything you move or download onto the desktop will automatically get a color label (as long as the extensions are in the script). Feel free to customize the color assignments, and add as many extensions to the colors in the script as you'd like.
    •    
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (7 votes cast)
 
[24,873 views]  

Automatically attach color labels to files | 7 comments | Create New Account
Click here to return to the 'Automatically attach color labels to files' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Automatically attach color labels to files
Authored by: ianeiloart on Apr 11, '07 08:47:26AM

Nice tip, but I'm curious about the color coding scheme. To my eyes, it looks arbitrary - I don't see the connections between, say, the red files.

---
Ian Eiloart



[ Reply to This | # ]
Automatically attach color labels to files
Authored by: aafuss on Apr 11, '07 07:49:06PM

Very useful tip-I used the script on a folder named new files.



[ Reply to This | # ]
Automatically attach color labels to files
Authored by: tubbyman on Apr 14, '07 04:41:35PM

My colors are set so that similar type files will have different colors. eg

-- gif is different than jpeg is different than bmp, etc..
-- mov is different than avi is different than asf

I do a lot of workflow stuff, and I often have many versions of the same type file in the same folder. I like to see what has been processed and what has not. I explicitly tried to make all different formats of, say, images, a different color.

If you wanna mod it to make all images of any format the same color, go nuts, it just happens to be different than what I use it for.



[ Reply to This | # ]
Automatically attach color labels to files
Authored by: ehouwink on Apr 14, '07 09:18:17AM
With this mod, the script will first look for similar files with a different color and apply that color, if not successful, do the original thing.

on adding folder items to this_folder after receiving these_items
	set fileColorList to {oranges:{"mpg", "mpeg", "bmp", "wma", "c", "cpp", "dmg", "doc"}, reds:{"asf", "jpg", "jpeg", "ram", "h", "hpp", "mpkg", "iso", "bin", "ppt", "pps"}, yellows:{"mov", "qt", "gif", "aif", "aiff", "htm", "html", "hqx", "tar", "xls"}, greens:{"mp4", "rgb", "rgba", "pcm", "js", "css", "cgi", "pkg", "gz", "z", "tgz", "pdf"}, blues:{"avi", "tif", "tiff", "mp3", "m", "zip", "eps", "ai"}, purples:{"wmv", "png", "wav", "scpt", "tbz", "bz2", "dat", "txt", "prefs"}, greys:{"rm", "ram", "ra", "psd", "pl", "xml", "plist", "sit", "rar", "rtf", "rtfd", "torrent"}}
	tell application "Finder"
		repeat with myFile in these_items
			try
				set {r, l} to {name extension of myFile, label index of myFile}
				set label index of myFile to (label index of first file of this_folder whose name extension is r and label index ≠ l)
			on error
				if the name extension of myFile is in oranges of fileColorList then
					set label index of myFile to 1
				else if the name extension of myFile is in reds of fileColorList then
					set label index of myFile to 2
				else if the name extension of myFile is in yellows of fileColorList then
					set label index of myFile to 3
				else if the name extension of myFile is in blues of fileColorList then
					set label index of myFile to 4
				else if the name extension of myFile is in purples of fileColorList then
					set label index of myFile to 5
				else if the name extension of myFile is in greens of fileColorList then
					set label index of myFile to 6
				else if the name extension of myFile is in greys of fileColorList then
					set label index of myFile to 7
				end if
			end try
		end repeat
	end tell
end adding folder items to


[ Reply to This | # ]
Automatically attach color labels to files
Authored by: tubbyman on Apr 14, '07 11:11:54PM

I forgot to add the accompanying applescript to actively change all of the color labels of all files in any selected folder (and subfolders). To use it, open it in script editor, save it out as an application, and run it. It will process all files in the folder you select. As with the folder action script, feel free to mod the behavior to do anything that you want.






tell application "Finder"
set processFolder to (choose folder with prompt "Select a folder to change label colors") as item

my digDeeper(processFolder)

end tell

on digDeeper(myFolder)
tell application "Finder"
my changeColors(myFolder)
set subFolders to every folder in folder myFolder
if (count of items in subFolders) is greater than 0 then
repeat with thisFolder from 1 to count of items in subFolders
set processSubFolder to item thisFolder of subFolders as string
my digDeeper(processSubFolder)
end repeat
end if
end tell
end digDeeper


on changeColors(myFolder)
set fileColorList to {oranges:{"mpg", "mpeg", "bmp", "wma", "c", "cpp", "dmg", "doc"}, reds:{"asf", "jpg", "jpeg", "ram", "h", "hpp", "mpkg", "iso", "bin", "ppt", "pps"}, yellows:{"mov", "qt", "gif", "aif", "aiff", "htm", "html", "hqx", "tar", "xls"}, greens:{"mp4", "rgb", "rgba", "pcm", "js", "css", "cgi", "pkg", "gz", "z", "tgz", "pdf"}, blues:{"avi", "tif", "tiff", "mp3", "m", "zip", "eps", "ai"}, purples:{"wmv", "png", "wav", "scpt", "tbz", "bz2", "dat", "txt", "prefs"}, greys:{"rm", "ram", "ra", "psd", "pl", "xml", "plist", "sit", "rar", "torrent", "rtf", "rtfd"}}

tell application "Finder"

try
set (label index of every file of item myFolder whose name extension is in oranges of fileColorList) to 1
end try
try
set (label index of every file of item myFolder whose name extension is in reds of fileColorList) to 2
end try
try
set (label index of every file of item myFolder whose name extension is in yellows of fileColorList) to 3
end try
try
set (label index of every file of item myFolder whose name extension is in blues of fileColorList) to 4
end try
try
set (label index of every file of item myFolder whose name extension is in purples of fileColorList) to 5
end try
try
set (label index of every file of item myFolder whose name extension is in greens of fileColorList) to 6
end try
try
set (label index of every file of item myFolder whose name extension is in greys of fileColorList) to 7
end try


end tell

end changeColors




[ Reply to This | # ]
Automatically attach color labels to files
Authored by: butaka on May 07, '11 12:37:15AM

My need was to have every file or folder that gets copied to a specific drive be color coded to that drive's color. I named my hard drives after the color (Not required. Just helpful in keeping things organized). I do video editing and knowing which drive a file resides on is very helpful for file management.

I created the following Folder Action script and assigned the script to the drive based on a few different scripts I've seen. My disk name is "YELLOW" (yours is whatever you named it) and the "3" is the number for the yellow label color. (Orange is 1, Red is 2, Yellow is 3, Blue is 4, Purple is 5, Green is 6, and Gray is 7). Keep in mind that I know very little about apple script commands or arguments. So, the only thing I could figure out is how to tell the drive to color code everything on the drive every time an item is copied to it. I would prefer if just the item that I copy to the drive be what gets color coded at that time. But, I couldn't get that to work. So here's what I have:

on adding folder items to this_folder after receiving these_items
tell application "Finder"
set label index of every item of entire contents of disk "YELLOW" to 3
end tell

(47274)

end adding folder items to



[ Reply to This | # ]
Automatically attach color labels to files
Authored by: nve5009 on Jul 23, '12 10:15:18AM

Hi,

Sorry to bump an old thread, but my question is almost identical to what tubbyman posted. I used the code in his last post and it works almost perfectly for what I need. If I wanted to also label the chosen folder and each subfolder what could I add to the code.

Thank you!



[ Reply to This | # ]