I want to be able to automatically assign a red tag to any folder/file that is dropped into a folder sitting on my desktop. I've done some research about this and it seems like this can't really be done even with Automator or Smart Folders, even though it seems pretty simple.
Finder Tag – Auto-tagging Folders/Files upon Drop-in
finder-tag
Best Answer
Option 1: Using Hazel
You can auto-tag folders/files dropped into a folder using the commercial software Hazel, which according to its developer Noodlesoft, "watches whatever folders you tell it to, automatically organizing your files according to the rules you create."
Option 2: Using Folder Actions
You can auto-tag folders/files dropped into a folder using the Folder Actions feature of macOS. I wrote the following AppleScript based partly on one of Apple's default Folder Action Scripts and partly on a script provided in a discussion in the Apple Support Communities. I tested this script in Mac OS X 10.6.8, 10.9.5, and 10.11.6 and it worked in all three versions of macOS (but see the Important Caveat section below).
The first line of the script,
property label_color : {none:0, orange:1, red:2, yellow:3, blue:4, purple:5, green:6, gray:7}
, is not really necessary; I just included it to show which label index number corresponds to each color. You could remove the first line and changered of label_color
to2
and the script would have the same effect.There are a few ways to attach this AppleScript to a folder as a Folder Action Script. One way is to open Automator, create a new Folder Action, add a Run AppleScript action, and replace the content of the Run AppleScript action with this script—but this didn't work in my test. Another way, which worked in my test, is to save the script in either
/Library/Scripts/Folder Action Scripts/
(for use by any user) or in~/Library/Scripts/Folder Action Scripts/
(for use by the current user only), and then do the following steps:Important Caveat
Technically, the previous script only sets the file label, which is not exactly the same as a tag, as John Siracusa explained in his Ars Technica review of tags implementation in OS X 10.9; however, in Finder in OS X 10.9 and later, the result of the previous script will be indistinguishable from a tag. The previous script works in versions of Mac OS X 10.6 or later.
A more robust Folder Action Script that sets a red tag and label instead of only a red label (although, as I said, the results are indistinguishable in the Finder) can be found in the AppleScript given below.
The script given below requires that you first install James Berry's tag tool (which requires OS X 10.9 or later). It can be installed easily with the package manager Homebrew (
brew install tag
) or MacPorts (sudo port install tag
). If you install it with Homebrew, replace/opt/local/bin/tag
(which is the MacPorts path) with/usr/local/bin/tag
(which is the Homebrew path) in the script below.A third way to write the AppleScript (in OS X 10.9 and later) would be to install an AppleScript/Objective-C Library written by Shane Stanley called FileTagsLib and then replace the
do shell script
line in the script above with the appropriate command as described in the FileTagsLib documentation, but I have not tested this third option.