diff options
author | Mike Clarke <mike@lambdafunctions.com> | 2018-11-29 17:17:30 +0000 |
---|---|---|
committer | Mike Clarke <mike@lambdafunctions.com> | 2018-11-29 17:17:30 +0000 |
commit | 46760080c149ce7e61225330765c418b26174098 (patch) | |
tree | dd283401706e7292542b3c5617e3018e939e2b21 /ports/darwin_dmg/fileicon | |
parent | 68ae5111bbf372a32d1bf62f1ed18d34e0880078 (diff) |
Add Swift helper to set custom file icons
Diffstat (limited to 'ports/darwin_dmg/fileicon')
-rwxr-xr-x | ports/darwin_dmg/fileicon | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/ports/darwin_dmg/fileicon b/ports/darwin_dmg/fileicon new file mode 100755 index 0000000..1e1d2a2 --- /dev/null +++ b/ports/darwin_dmg/fileicon @@ -0,0 +1,33 @@ +#! /usr/bin/swift + +import Darwin +import Cocoa + +func die(_ msg: String) { + fputs("\(msg)\n", stderr) + exit(1) +} + +let name = CommandLine.arguments[0] + +/* + * We don't do anything with the 'set' at the moment; it's just there to + * reserve a space for a subcommand to allow for future expansion without + * changing the interface. + */ +if CommandLine.argc == 4 && CommandLine.arguments[1] == "set" { + let target_file = CommandLine.arguments[2] + let icon_file_name = CommandLine.arguments[3] + + if let icon = Cocoa.NSImage.init(contentsOfFile: icon_file_name) { + if !NSWorkspace.shared.setIcon(icon, forFile: target_file) { + die("Failed to set icon for '\(target_file)'") + } + } + else { + die("Failed to read icon file '\(icon_file_name)'") + } +} +else { + die("Usage: \(name) set FILE ICON_FILE") +} |