Automatically attach color labels to files

Apr 11, '07 07:30:00AM

Contributed by: tubbyman

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.

Comments (7)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20070408193708936