The macOS dock only displays images that are in .icns format. If you would like to use a custom logo for the Self Service dock icon you need to convert your image into this format.
The following script needs a few adjustments in order to make an .icns file. Substitute the quoted strings after pathToImage, imageName, and addPadding. The script will take those three variables and create a MyIcon.icns file in the folder that was specified. The image provided needs to have equal width and height, preferably 1024x1024px, and be in PNG format.
You can save the entire script as a .sh file, edit the two variables, and save the changes. In Terminal run bash /path/to/.shfile or drag the .sh file directly into Terminal after bash. Execute the command by hitting enter and the .icns file will be produced.
Note: These are Bash command language scripts and should be executed from a local macOS Terminal session on an Addigy admin's device.
Note: A quick way to tell which addPadding setting you need is to open the PNG in Preview.
- If the PNG touches the edges of the canvas, use Yes.
- If the PNG has a clear transparent border, use No.
#!/usr/bin/env bash
# ============================================================
# EDIT THESE LINES
# ============================================================
# Folder containing your PNG. No trailing "/".
# Example: "$HOME/Downloads"
pathToImage="/path/to/your/folder"
# Your PNG's file name, with a leading "/".
# Must be a 1024x1024 PNG with a transparent background.
imageName="/YourIcon-1024.png"
# "yes" = PNG is full-bleed (like Icon Composer exports), so add the macOS margin.
# "no" = PNG already has the margin built in, so only convert to .icns.
addPadding="yes"
# ============================================================
# Nothing below this line needs editing.
# The finished file is saved as MyIcon.icns in the folder above.
# ============================================================
orig="${pathToImage}${imageName}"
padded="${pathToImage}/padded_tmp.png"
jxa="${pathToImage}/pad_tmp.js"
set="${pathToImage}/MyIcon.iconset"
if [ ! -f "$orig" ]; then
echo "Image not found: $orig"
echo "Check pathToImage and imageName at the top of the script."
exit 1
fi
# Optionally shrink the artwork to 824x824 and center it on a
# transparent 1024x1024 canvas. This adds the margin macOS expects.
if [ "$addPadding" = "yes" ]; then
cat > "$jxa" <<'EOF'
ObjC.import('AppKit');
function run(argv) {
var img = $.NSImage.alloc.initWithContentsOfFile(argv[0]);
var rep = $.NSBitmapImageRep.alloc.initWithBitmapDataPlanesPixelsWidePixelsHighBitsPerSampleSamplesPerPixelHasAlphaIsPlanarColorSpaceNameBytesPerRowBitsPerPixel(
$(), 1024, 1024, 8, 4, true, false, $.NSDeviceRGBColorSpace, 0, 0);
$.NSGraphicsContext.saveGraphicsState;
$.NSGraphicsContext.setCurrentContext($.NSGraphicsContext.graphicsContextWithBitmapImageRep(rep));
img.drawInRect($.NSMakeRect(100, 100, 824, 824));
$.NSGraphicsContext.restoreGraphicsState;
var data = rep.representationUsingTypeProperties($.NSBitmapImageFileTypePNG, $());
data.writeToFileAtomically(argv[1], true);
}
EOF
osascript -l JavaScript "$jxa" "$orig" "$padded" || { echo "Padding failed"; rm -f "$jxa"; exit 1; }
rm -f "$jxa"
else
cp "$orig" "$padded"
fi
# Build the iconset at every size macOS needs
rm -rf "$set"
mkdir -p "$set"
sips -z 16 16 "$padded" --out "$set/icon_16x16.png"
sips -z 32 32 "$padded" --out "$set/icon_16x16@2x.png"
sips -z 32 32 "$padded" --out "$set/icon_32x32.png"
sips -z 64 64 "$padded" --out "$set/icon_32x32@2x.png"
sips -z 128 128 "$padded" --out "$set/icon_128x128.png"
sips -z 256 256 "$padded" --out "$set/icon_128x128@2x.png"
sips -z 256 256 "$padded" --out "$set/icon_256x256.png"
sips -z 512 512 "$padded" --out "$set/icon_256x256@2x.png"
sips -z 512 512 "$padded" --out "$set/icon_512x512.png"
sips -z 1024 1024 "$padded" --out "$set/icon_512x512@2x.png"
# Convert to .icns and clean up temporary files
iconutil -c icns "$set" && rm -rf "$set" "$padded"
echo "Done: ${pathToImage}/MyIcon.icns"After running the script, the .icns file will be located in the directory the source (.png) file came from.
Alternatively, you can use third party sites or tools to create .icns files from other image types.