Is it possible for an AppleScript .app file to retain its custom icon, even after edits have been made to the code?
I've created an AppleScript .app file in Script Debugger.app.
I assigned a custom icon to this .app file by pasting a new icon over the default icon in the application's Get Info window in Finder. The custom icon is set immediately.
However, when I open the app in Script Debugger or Script Editor, to edit the code, and then resave the file, the custom icon disappears.
On save, the following icon immediately takes the place of the custom icon:
Of course, having to go through the process of setting the custom icon every time that I save (i.e., edit) the file is an inconvenience.
Is there a way for my custom application icon to remain in place, even after the .app file has been modified?
Here is a similar post:
App made in Applescript; Icon won't change
The answer to the above post gave me the idea to delete the default icon file located at /Contents/Resources/applet.icns
(which I accessed by right-clicking the .app file in Finder and clicking the Show Package Contents context menu item). I then pasted my custom icon into this Resources
folder, and renamed my icon applet.icns
.
The effect of this was a custom icon in informational
dialogs in my AppleScript application, but it did not actually change the actual application icon (i.e., the icon that is inserted into the Dock while the application is running). But, at least this custom dialog icon did remain in place upon re-saving/editing the AppleScript code.
Solution 1:
I followed your exact same procedure and found the exact same problem on operating system Sierra as well. After trying a few things I decided (in addition to changing the main Applications icon in the get info window) to do the exact same thing in the get info window of the applet.icns file and change it's icon as well. I then opened that script editor app in scripteditor and saved the file. The new icons remained as I changed them. Tested in script debugger also and my custom icons remained untouched.
UPDATE:
This following AppleScript code will permanently change the default applet.icns
file of your AppleScript applets to any other .icns
file of your choosing so that even after editing and re-saving the AppleScript applet, your custom icon will be retained.
property destinationSuffix : "Contents/Resources/applet.icns"
activate
set chosenApp to (choose file with prompt ¬
"Choose The Application Whose Icon You Would Like To Change" of type ¬
"APPL" with multiple selections allowed)
activate
set iconFile to (choose file of type "com.apple.icns" with prompt ¬
"Choose The Replacement .icns File")
repeat with thisItem in chosenApp
set replaceThisIcon to POSIX path of thisItem & destinationSuffix
try
do shell script "cp " & quoted form of POSIX path of iconFile & " " & ¬
quoted form of replaceThisIcon & " ; touch " & quoted form of POSIX path of thisItem
end try
end repeat