I want to write/find a script that applies a colour label and background colour to all items below a particular folder.
I have split my Documents folder into six core themes, each folder having a different colour label and associated background color. But this means documents added since the last label-and-background update do not have the correct properties - I want the coloring system to be auto-inherited downward.
I found the following code…
tell application "Finder"
set items_ to selection
repeat with item_ in items_
try
set label index of item_ to 3
on error e
display dialog e
end try
end repeat
end tell
… that applies color 3 to the items selected in Finder.
But what I need is to add the background color and to ensure that the colors are applied to every child folder and file beneath the selected one.
In fact, what I’d like is for this to take place automatically, perhaps with a Folder Action, so that, whenever a new item is added to one of the folders, it acquires the label and background color of the absolute parents. Or, perhaps with an Automator workflow, you would routinely update the file properties at a set interval.
Not sure if I would need one script for each color or (better) one script to handle it all.
A newcomer to scripting but keen to learn. Look forward to it. Ta.
To adapt it for more specific use, you could simply extract the changeColors handler, calling it directly using specified parameters - something like this:
to changeColors at s to l against b
tell application "Finder" to repeat with i in s
set i's label index to l
if i's class is folder then
set background color of icon view options of i's window to b
my (changeColors at (i's items) to l against b)
end if
end repeat
end changeColors
tell application "Finder" to set s to selection
if (count s) > 0 then changeColors at s to 3 against {65535, 52428, 0}
So it picks up the selected file/folders label and background color properties and applies them to every file contained downward from there. Great.
Related uses I was thinking of/ways I’d like to look at extending this:-
Quicker - Contingency so that the color scheme is not re-applied if a file already has it (or, if the file has label 0 and white/blank background color, do apply the scheme).
Background color - Remember that, when you do a View Options (cmd-J) on a folder, the “Background:” option has three states - White (default), Color and Picture - so that might want to take not just an RGB value but the others too (default would restored values) in the same way label 0 would for icon labels.
No interface - can you just remove chooseBackground and chooseLabel and have it still work, not requiring confirmation of the inherited values?
Automatic - Only apply color schemes to documents/folders newly created/added in the master parents. Maybe scope for a Folder Action? Wonder how I can do this.
Okay. When I used that code verbatim, there was no effect.
What does just using this portion do? I guess it involves hard-coding the color values in there - I can see the background color but I don’t where the label color integer is here.
I’ve been using something like this to change folders:
on open droppedItems
try
repeat with thisItem in droppedItems
if folder of (info for thisItem without size) is true then
tell application "Finder"
set icon size of icon view options of thisItem's window to 128
set background color of icon view options of thisItem's window to {65535, 52428, 0}
end tell
end if
end repeat
on error errorMsg number errorNum
display alert "Error " & errorNum message errorMsg buttons "Cancel" default button 1
end try
end open
However, this particular script doesn’t work recursively.