I\'m trying to set the colored labels shown by the finder. The only function I know is setResourceValue. But this needs localized names!
I could image my mother lang
I got it working without having to know the color name, thanks to the new URLResourceValues() struct and the tag numbers.
Knowing that each of these tag numbers represents a tag color:
0 None
1 Grey
2 Green
3 Purple
4 Blue
5 Yellow
6 Red
7 Orange
Make a URL of your file:
var url = URL(fileURLWithPath: pathToYourFile)
It has to be a var because we are going to mutate it.
Create a new URLResourceValues instance (also needs to be a variable):
var rv = URLResourceValues()
Set the label number like this:
rv.labelNumber = 2 // green
Finally, write the tag to the file:
do {
try url.setResourceValues(rv)
} catch {
print(error.localizedDescription)
}
In our example we've set the number tag to 2 so now this file is labeled with green color.