How do I have the button icon change to the alternate icon when pressed?
For example, I want the icon to switch from the USA Flag to the Japanese Flag when I'm switching between keyboards.
How do I have the button icon change to the alternate icon when pressed?
For example, I want the icon to switch from the USA Flag to the Japanese Flag when I'm switching between keyboards.
Convert the picture to base64 format and output it in json format, for example
set activeKbdLayout to do shell script "defaults read " & "~/Library/Preferences/com.apple.HIToolbox.plist"
if activeKbdLayout contains "keylayout.ABC" then
set activeKbdLayout to "iVBORw0KGgoAAAANSUhEUgAAADwAAAAkCAYAAADVeVmEAAABHmlDQ1BBcHBsZSBSR0IAACiRlY69SsNgFIafLxaUDqFIKC7ChwUnf0rvIM1QBIcaiiSZTNIQxVg/0s+fTi69CC+ii6OD4AXopHgFDu6CdHBwSCWIYPFZznveczjvAWMlVCozanAy0LnbaUvPD+TiKxXq1GhghfFQ2d3uLsB3/cnHCwLgaTNUKvs9/5NqPxnGwCfQj1WuQRwAjQutNIgxYEXHSoO4Bqzc8wMQE8BKC30PWFGhnwEr77kOiDfAjAo9Bcy05zpgLAHmLBegaiuVJdLttP/5/Dx0cqkBnFM1yo/SQy2LpJ1BvLUhW81WEzw/kMX2+x4CEPWH0ispvdEd2C5UbktvfwqTbVhdKL31NVi+ghsVn+XnszNCPMK8/gtge0uOCkjqVgAAAAlwSFlzAAAWJQAAFiUBSVIk8AAABRJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDYuMC1jMDAyIDc5LjE2NDM1MiwgMjAyMC8wMS8zMC0xNTo1MDozOCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwd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3YuiKExNTbFx40aklDQ1NfHggw86ielqzCUwTdMuR4Xg2oT/owmAeQf3uxDOz8+nqakJgNHRUTKZDJZlkclkUFUVr9eL1+vll19+QVEU1q9f74TlXDgDBIPBeRr8SuTm5hIKhdi9ezeqqmYdqgMBgsslSkqJx+NZKt+lZelkMnl536vCqKenhxMnTpCfn09dXZ0zfmV/vJDenZOXfr/fkaLXghCCRCJBKBSaFwGLwZIIw+VMeWUWDYVCvP3220QiEWpqali5cuWSnQAc3b13715njatJz+3Z29tLU1PTPJm6GCyqLMViMSYmJvj666+dTkUIwblz53jllVcYGBhg+fLl7Ny5c0Glcz24XC7i8TgHDhygsLDwurcnhGBsbAzbtm/qz4IFvUulUuzZs4fu7m4uXbqEpmnU1NSQSCRobm7mo48+Ijc3l82bN7N9+/YsWymlo5Yymcx197Bt2+nADhw44Nzk9W5YCEE8Hsfv91839G+asK7reDwexsfHMQyD2tpanvz7k7hcLqqrqwkGgzz11FM0NzfPs517cCalvKEKEkKQTqdxuVw899xzFBUVOYnpSsy1if/6+WcOfvzxdQXKjbCg8IDLPev4+DgARUVF3HXXXQDE43EGBwdZt27dNUuNZVkMDg4ihGDNmjXXnANw6dIl+vr6EELw2GOPLdjbnr9wgaP9/aiqyqZNm7KqwQKILorwHYSostRHp39WzDUwyujo6O325ZZACMHIyAjKoUOHbrcvtwwdHR0oBw8e5Luh7263L384jh07xsGDB1Ft2/7H8Olhqqqqsh7B3EkY/Ocge/bsYWxszCUqKirORiNR371l99LQ0MCWLVuoqKi4acX0/wLLshgeHubQoUN0dXVx5swZ8vLyov8GDYqQEX22tpQAAAAASUVORK5CYII="
end if
return "{"text":" ", "icon_data":"" & activeKbdLayout & ""}"
Can help please how do you do it?