Last active
November 28, 2020 01:35
-
-
Save mattcox/8a5d68a0e6b768be3e393aeadbed0af3 to your computer and use it in GitHub Desktop.
This file contains 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 Cocoa | |
import Foundation | |
let pathToImage = "/some/path/to/an/image.png" | |
let pathToFolders = URL(fileURLWithPath: "/Some/Folder/Path/") | |
guard let image = NSImage(contentsOfFile: pathToImage) else { | |
fatalError("Unable to load image.") | |
} | |
do { | |
let fileManager = FileManager.default | |
let directoryContents = try fileManager.contentsOfDirectory(at: pathToFolders, includingPropertiesForKeys: [.isDirectoryKey], options: FileManager.DirectoryEnumerationOptions(rawValue: 0)) | |
for subPathURL in directoryContents { | |
if (try subPathURL.resourceValues(forKeys: [.isDirectoryKey])).isDirectory ?? false { | |
Cocoa.NSWorkspace.shared.setIcon(image, forFile: subPathURL.path, options: NSWorkspace.IconCreationOptions(rawValue: 0)) | |
} | |
} | |
} catch { | |
print("Something went wrong...") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment