In Script Editor.app, paste this following AppleScript code into a new document then name and save it as a “scpt” file to /Users/YOUR_SHORT_NAME/Library/Workflows/Applications/Folder Actions folder.
on adding folder items to theFolder after receiving theNewItems
-- Called after items have been added to a folder
-- theFolder is a reference to the modified folder
-- theNewItems is a list of references to the items added to the folder
repeat with i from 1 to count of theNewItems
try
set thisFile to item i of theNewItems
tell application "Finder"
if name extension of thisFile is "eaf" then
set label index of theFolder to 2 -- 2 = Red
end if
end tell
end try
end repeat
end adding folder items to
(* Anytime Files Are Removed From The Folder That
This Folder Action Is Attached, If None Of The Remaining Files
(If Any) Do Not Have The Name Extension "eaf", The Red Label
Tag Will Be Removed From The Containing Folder *)
on removing folder items from theFolder after losing removedItemNames
-- Called after items have been removed from a folder
-- theFolder is a reference to the modified folder
-- removedItemNames is a list of names of items removed from the folder
delay 3 -- A Little Buffer If Removed Files Are Large Or Alot
tell application "Finder"
set fileRef to a reference to (files of theFolder whose name extension is "eaf")
if contents of fileRef is {} then
set label index of theFolder to 0
end if
end tell
end removing folder items from
After your file is saved to that location, you can attach that Folder Action to any folder of your choice by ctrl + click
the folder in Finder.app then select “Services” then “Folder Actions Setup…”. From there it’s pretty much self-explanatory. Just attach your new folder actions script to the folder and you should be good to go.
Now anytime a file with the extension “eaf” is added to that folder, the “Red” Finder tag will be added to the folder. On the flip-side, I also added the functionality to monitor the folder when items are removed that if none of the remaining files have the name extension “eaf”, the “Red” Finder tag will be removed from the folder.
If you already have a bunch of “eaf” files scattered all over your computer within different folders and you would like to add the “Red” Finder label tag to the containing Folders of those “eaf” files then… In Script Editor.app, paste this following AppleScript code into a new document and run the script.
set containingFolders to {}
set theFiles to paragraphs of ¬
(do shell script "find ~ -type f -iname '*.eaf'") as list
tell application "Finder"
repeat with i from 1 to count of theFiles
set thisItem to item i of theFiles
set aContainer to container of ¬
(thisItem as POSIX file as alias) as alias
if aContainer is not in containingFolders then ¬
set end of containingFolders to aContainer
end repeat
repeat with thisContainer in containingFolders
set label index of thisContainer to 2
end repeat
end tell
.eaf
) I'd love the folder get a red Finder tag, telling me it's been transcribed.eaf
then add this tag to the folder in which it sits" (not to the file itself) – if you have a script that does something like that I'd be very grateful.