I added the shortcuts to Quick Actions so that I can just right-click PNGs anywhere on my system and create an ICNS file (in the same directly/folder where the PNG is located).
But I get the following error message for every image size the script tries to create:
error: Warning: tempicon.iconset/icon_512x512@2x.png not a valid file - skipping
80sTherapy. I couldn’t get the shell script to work, but I found an AppleScript that does what you want (here), and it worked as expected when run from within a shortcut on my Sonoma computer. To test, install the shortcut then select the shortcut from an image file’s Quick Actions’ context menu.
Because it works as written, I didn’t review the AppleScript other than to change the output folder and to fix one error. Also, I didn’t test the other scripts provided by Nigel and Shane (which are almost certainly much better). The Shortcuts app does a good job of resizing images, and all the sips calls might best be avoided and the Resize Image action used instead. I’ll look at this FWIW.
80sTherapy. I’m glad to hear that you got your shortcut working well.
I wrote a PNG to ICNS shortcut that primarily uses Shortcut actions. The PNG image should be generally square–otherwise the icon will have a squeezed appearance. The following screenshot only shows a portion of the shortcut.
The shortcut will prompt several times when first run for permission to access folders and delete a temporary folder. These are an annoyance, but they disappear fairly quickly.
FWIW, the following shortcut extracts and creates a folder of PNG files from an ICNS file. The number and resolution of the PNG files is dependent on what’s in the ICNS file. The shortcut is run by way of the ICNS file’s Quick Action context menu.
A forum member inquired if my PNG to ICNS shortcut could be modified to convert multiple images at one time, and I’ve included that below. Given the amount of work done by the shortcut, and the use of a shell utility, I have reservations as to the shortcut’s reliability, so it’s FWIW. The timing result with 10 PNG images, each of which contained 170 KB, was 4.6 seconds. The following screencapture only shows a portion of the shortcut.
The Apple documentation contains the following (here):
Ideally, you would supply a complete set of icons. However, it is not a requirement to have a complete set; the system will choose the best representation for sizes and resolutions that you don’t supply. Each icon in the set is a hint to the system as to the best representation to use.
So, I modified my shortcut to allow the user to select those icons that will be included in the icon set. Rather then prompt the user first for the PNG files and then for the icons to include, I modified the shortcut to work on PNG files selected in a Finder window. I was uncertain what the text of the individual items in the choose from list dialog should be, so I opted for simplicity and used the items in the list as written.
BTW, I ran this shortcut on my 2023 Mac mini with 10 screencapture files each of which contained 488 KB, and the shortcut created the ICNS files without issue. So, the shortcut does seem to be reasonably robust, although there’s certainly a limit to this.
That’s great. Thanks again for all the help! I really do try to come up with my own solutions, but not having any coding experience makes it challenging to understand the logic.