Skip to content

Instantly share code, notes, and snippets.

@ole
Created February 2, 2023 11:43
Show Gist options
  • Save ole/b71613c2fec5eb1a547fded779d4e16b to your computer and use it in GitHub Desktop.
Save ole/b71613c2fec5eb1a547fded779d4e16b to your computer and use it in GitHub Desktop.
Assign colors (as shown in the macOS Finder) to files
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)
}
}
@ole
Copy link
Author

ole commented Feb 2, 2023

2023-02-02-Finder-file-colors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment