Created
February 2, 2023 11:43
-
-
Save ole/b71613c2fec5eb1a547fded779d4e16b to your computer and use it in GitHub Desktop.
Assign colors (as shown in the macOS Finder) to files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
enum FinderColor: Int { | |
case noColor = 0 | |
case grey = 1 | |
case green = 2 | |
case purple = 3 | |
case blue = 4 | |
case yellow = 5 | |
case red = 6 | |
case orange = 7 | |
} | |
extension URL { | |
/// Assigns a color to the file/directory this URL identifies. | |
/// | |
/// The color is displayed as a label by the macOS Finder. | |
/// macOS stores this tag as an extended attribute on the file. | |
mutating func setFinderColor(_ color: FinderColor) throws { | |
var resourceValues = URLResourceValues() | |
resourceValues.labelNumber = color.rawValue | |
try setResourceValues(resourceValues) | |
} | |
} |
Author
ole
commented
Feb 2, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment