MacOS – How to set a custom icon inside a signed Apple Script application

applescriptcode-signingiconmacos

I'm using Apple Script to distribute a signed applet, and would like to use a custom icon. However, as soon as I export it from Script Editor, the bundle loses the custom applet.icns file I put in it. It's reverted to the standard script icon (see screenshot).

enter image description here

How do I export my script as an app without losing my custom icon?

If not possible: are there other ways to sign an Apple Script application bundle on OS X 10.10? This would allow me to do a manual icon replacement and sign the bundle afterwards.

Important twist: Replacing the applet.icns file afterwards is not an option, as the bundle won't pass signature validation anymore. In short, users get a damaged app error when launching the app, unless they have lowered their OS X security.

Best Answer

You can force codesign after You change bundle content. In Terminal.app use something like this:

 codesign -f -s [identity] /path/to/bundle

For more info please read man codesign.