Hammerspoon: Is putting an hs.image as icon on hs.menubar supposed to work?

Created on 3 Dec 2020  路  4Comments  路  Source: Hammerspoon/hammerspoon

I tried putting a jpeg image as an icon in a menubar but it's just showing up as a white square.

(I tried with my avatar here from github for example, results in this behavior:

image

menu = hs.menubar.new()
local img = hs.image.imageFromURL(url):setSize({h=16, w=16})
menu:setIcon(img)
menu:setTitle('hello world')

i tried dumping the image to a string and it looks ok as a string. but is showing up as a white square in the menu.

Most helpful comment

This works for me...

menu = hs.menubar.new()
url = 'https://avatars1.githubusercontent.com/u/1171003?s=88&v=4'
local img = hs.image.imageFromURL(url):setSize({h=16, w=16})
menu:setIcon(img,false)

I used your avatar url for tests...

ychlm5gz4wzrk67kv08fipianmi1qlnv

You need to use setIcon with false, otherwise it would be used as a template, which converts it to b/w for displaying with normal- and darkmode.

All 4 comments

I don't think JPG works - try PNG or PDF

Ah that's unfortunate, I'm getting it from a url, so I have no control over it.
I wish I could easily convert it on the fly, but I don't think I want to get into saving it to disk, converting and then loading from disk again.

EDIT: I tried with a local PNG and it also didn't work.

This works for me...

menu = hs.menubar.new()
url = 'https://avatars1.githubusercontent.com/u/1171003?s=88&v=4'
local img = hs.image.imageFromURL(url):setSize({h=16, w=16})
menu:setIcon(img,false)

I used your avatar url for tests...

ychlm5gz4wzrk67kv08fipianmi1qlnv

You need to use setIcon with false, otherwise it would be used as a template, which converts it to b/w for displaying with normal- and darkmode.

@dasmurphy - wow it works, thank you very much!

I think during my tests I noticed that parameter and I tried passing true there but that's what I get for not reading the docs carefully enough, I totally missed that true is the default

Was this page helpful?
0 / 5 - 0 ratings

Related issues

asmagill picture asmagill  路  4Comments

agzam picture agzam  路  3Comments

jasonrudolph picture jasonrudolph  路  4Comments

specter78 picture specter78  路  3Comments

aaronjensen picture aaronjensen  路  3Comments