Created
February 25, 2023 15:27
-
-
Save danielbayley/d7fd4e495eab6db20f718d2de27dd3cd to your computer and use it in GitHub Desktop.
Set icon for file or folder from image, existing app or folder.
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
#! /usr/bin/xcrun swift | |
import Cocoa | |
let args = CommandLine.arguments[1...] | |
let (target, icon) = (URL(fileURLWithPath: args.first!).path, args[2]) | |
var folder: ObjCBool = false | |
FileManager.default.fileExists(atPath: icon, isDirectory: &folder) | |
let image: NSImage = folder.boolValue | |
? NSWorkspace.shared.icon(forFile: icon) | |
: NSImage(byReferencingFile: icon)! | |
NSWorkspace.shared.setIcon(image, forFile: target) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment