-
Notifications
You must be signed in to change notification settings - Fork 295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace volume file's icon #132
Comments
The referenced other project of the same name appears to use a random compiled binary embedded in the source code without any source code provided to set the dmg icon, which seems pretty sketchy. Swift provides an API to set this (there are also command-line tools, but they appear to be deeply deprecated), so I wrote a simple swift script to set it (warning: I'm not a Swift developer) that might be helpful to others (or incorporated into this project). I'm currently building this and calling it just after the import Foundation
import AppKit
// Apple deprecated their command line tools to set images on things and replaced them with a
// barely-documented swift function. Yay!
// Usage: ./seticon /path/to/my.icns /path/to/some.dmg
let args = CommandLine.arguments
if args.count != 3 {
print("Error: usage: ./seticon /path/to/my.icns /path/to/some.dmg")
exit(1)
}
var icns = args[1]
var dmg = args[2]
var img = NSImage(byReferencingFile: icns)!
if NSWorkspace.shared.setIcon(img, forFile: dmg) {
print("Set \(dmg) icon to \(icns) [\(img.size)]")
} else {
print("Setting icon failed, don't know why")
exit(2)
} $ ./seticon my.icns some.dmg
Set some.dmg icon to my.icns [(128.0, 128.0)] (To avoid any potential licensing concerns: I provide this under the same MIT license as this create-dmg project). |
Thank you very much for this. |
Would be helpful if the volume file's icon also use the
--volicon
value to align with the mounted volume. I noticed this because the unrelated create-dmg does set both the volume and volume file icon, yet this shell-based tool doesn't seem to do that.The text was updated successfully, but these errors were encountered: