import AppKit import Foundation let arguments = Array(CommandLine.arguments.dropFirst()) let usage = "Usage: swift set_macos_file_icon.swift \n" if arguments == ["--help"] || arguments == ["-h"] { print(usage, terminator: "") exit(0) } guard arguments.count == 2 else { fputs(usage, stderr) exit(2) } guard FileManager.default.fileExists(atPath: arguments[1]), let icon = NSImage(contentsOfFile: arguments[0]), NSWorkspace.shared.setIcon(icon, forFile: arguments[1], options: []) else { fputs("Failed to set file icon: verify the icon and target paths\n", stderr) exit(1) }