Programmatically change Safari browser extension icon?

I have a disabled Safari browser extension. What I would like to do is programmatically change the toolbar icon when the user goes into disabled mode.

Is there an API that will allow me to achieve this, and if so, what is it?

+5
source share
1 answer

Any toolbar items that you can reference as an array in

safari.extension.toolbarItems

Each toolbar item will have an image property that you can change. This will immediately change the toolbar icon.

// Change the toolbar icon.
var changeToolbarIcon = function(newIconName) {
  var iconUri = safari.extension.baseURI + 'icons/' + newIconName;
  safari.extension.toolbarItems[0].image = iconUri;
};

Safari Documentation

+10
source