import AppKit // macOS displays the supplied silhouette; unlike iOS it does not mask an opaque master. // Keep the approved square master intact and derive a padded Mac icon from it. let sourceURL = URL(fileURLWithPath: CommandLine.arguments[1]) let outputURL = URL(fileURLWithPath: CommandLine.arguments[2]) guard let source = NSImage(contentsOf: sourceURL), let bitmap = NSBitmapImageRep(bitmapDataPlanes: nil, pixelsWide: 1024, pixelsHigh: 1024, bitsPerSample: 8, samplesPerPixel: 4, hasAlpha: true, isPlanar: false, colorSpaceName: .deviceRGB, bytesPerRow: 0, bitsPerPixel: 0), let context = NSGraphicsContext(bitmapImageRep: bitmap) else { fatalError("Cannot load or render the app’s icon") } NSGraphicsContext.saveGraphicsState() NSGraphicsContext.current = context context.imageInterpolation = .high let tile = NSRect(x: 100, y: 100, width: 824, height: 824) NSBezierPath(roundedRect: tile, xRadius: 184, yRadius: 184).addClip() source.draw(in: tile, from: .zero, operation: .copy, fraction: 1) NSGraphicsContext.restoreGraphicsState() guard let png = bitmap.representation(using: .png, properties: [:]) else { fatalError("Cannot encode the app’s icon") } try png.write(to: outputURL)