I've gotten it working. The rules for the png file are very lenient; I tested with a png containing lots of different color and alpha values. The main hurdle for me was that ukelele doesn't seem consistent about when to add a KLInfo_<name> dict to the Info.plist. Even after I fiddled with the collection checkboxes, ukelele often wouldn't write an updated Info.plist. I suspect this may be the problem for some of the above people.
I also had to pay attention to whether Ukelele was setting
CFBundleIdentifier properly; it would often write "org.sil.ukelele.keyboardlayout." with no name.
So here is what I did:
- Author a .png file that has alpha in it. It can have color too, but the color values are entirely ignored. You don't need to restrict yourself to alpha values of 0.0 and 1.0; in-between values will render in shades of grey
- Convert it to a .icns. I only bothered adding 16x16 and 32x32. These two utilities are in /usr/bin and I believe they don't require xcode to be installed.
mkdir -p your.iconset
sips -z 16 16 your.png --out your.iconset/icon_16x16.png
sips -z 32 32 your.png --out your.iconset/icon_...@2.png
sips -z 32 32 your.png --out your.iconset/icon_32x32.png
sips -z 64 64 your.png --out your.iconset/icon_...@2.png
iconutil -c icns your.iconsetNow you have a file called
your.icns.
In Ukelele, attach
your.icns to the keyboardlayout, set the "Template" flag, and save.
Open up the
<yourname>.bundle/Contents/Resources/Info.plist file in a text editor and verify that it looks correct. (Use right-click → Show Package Contents if you have trouble examining a bundle). You want to see a correct
CFBundleIdentifier, a
KLInfo for each of your layouts, correct values of
TISInputSourceID and
TISIconIsTemplate, and so on.
Eventually after enough jiggling the handle, I would get a bundle with a good Info.plist.
Responding to some specific comments made above:
> ... but haven't figured out how to do it in an ICNS ...
The .icns doesn't (and can't) specify whether it's a "template"; it's an icon like any other. The "is template" setting is found in the .keyboardlayouts bundle; specifically the key TISIconIsTemplate in Info.plist. That setting governs whether the specified icon is treated as a template. If that key is set but your your .icns isn't authored properly, for example if it is entirely opaque, the menu bar icon will still react to light/dark mode, but it will look incorrect -- for example, like a fully-opaque black (or white) square.
> you have to use image2icon / Xcode / etc ...
Good news; the tools I used seem to come with macOS.