Skip to content
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

Open
paulrrogers opened this issue Apr 10, 2022 · 2 comments
Open

Replace volume file's icon #132

paulrrogers opened this issue Apr 10, 2022 · 2 comments

Comments

@paulrrogers
Copy link

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.

@jagerman
Copy link

jagerman commented Aug 29, 2022

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 create-dmg invocation to also set the icon of the dmg. It compiles with simply swiftc seticon.swift:

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).

@ednt
Copy link

ednt commented Aug 8, 2023

@jagerman

Thank you very much for this.
Now my build script is complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants