0

I could find in different places how to personalize the AppleScript icon: https://apple.stackexchange.com/questions/8299/how-do-i-make-an-applescript-file-into-a-mac-app Customize Applescript app icon

Apple also talks about the resolution of the different icon in a regular Xcode app: https://developer.apple.com/library/archive/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Optimizing/Optimizing.html

But what is the recommended resolution of an AppleScript icon app?

Nrc
  • 9,577
  • 17
  • 67
  • 114
  • The default applet.icns is a low resolution containing 4 images 1 each at 256 x 256, 128 x 128, 32 x 32 and 16 x 16 all at 72 pixels/inch. As to what's recommended, well I'd go by Apple's official documentation that you've linked in your question. – user3439894 Oct 01 '19 at 14:42

2 Answers2

1

Icon sizes are used by the system, not by AppleScript, so whatever conventions the system wants for 'regular' app should be used for an AppleScript app as well.

EDIT

Per the comments on one of the other answers, here's a script that will create an icns file with all suggested sizes from whatever image you choose:

set picFile to choose file with prompt "Choose an image to iconize." of type {"public.image"}
set workingFolder to POSIX path of (path to temporary items from user domain)
set outputFolder to POSIX path of (path to desktop from user domain)

set sizesList to {16, 32, 128, 256, 512}

tell application "System Events"
    set pictureFilePath to quoted form of (get POSIX path of picFile)
    set {pictureName, ext} to {name, name extension} of picFile
    if ext is not "" then
        set pictureName to text 1 through -((length of ext) + 2) of pictureName
    end if

    -- create iconset folder
    set iconsetFolder to make new folder at folder workingFolder with properties {name:pictureName & ".iconset"}

    -- cycle through sizes to create normal and hi-def sized icon images
    repeat with thisSize in sizesList
        set iconFilePath to POSIX path of iconsetFolder & "/" & my makeFileNameFromSize(thisSize, false)
        do shell script "sips -z " & thisSize & " " & thisSize & " " & "-s format png " & pictureFilePath & " --out " & iconFilePath
        set iconFilePath to POSIX path of iconsetFolder & "/" & my makeFileNameFromSize(thisSize, true)
        do shell script "sips -z " & thisSize * 2 & " " & thisSize * 2 & " " & "-s format png " & pictureFilePath & " --out " & iconFilePath
    end repeat

    -- create new icns file
    set iconsetPath to quoted form of (POSIX path of iconsetFolder as text)
    set outputPath to quoted form of (outputFolder & pictureName & ".icns")
    do shell script "iconutil -c icns -o " & outputPath & " " & iconsetPath
end tell

on makeFileNameFromSize(s, x2)
    set fileName to "icon_" & s & "x" & s
    if x2 then set fileName to fileName & "@2x"
    set fileName to fileName & ".png"
    return fileName
end makeFileNameFromSize

Caveats:

  • This puts the icns file on the desktop; that can be changed by changing the outputFolder variable.
  • This can throw an error if there are characters in the image file name that the shell interprets as meaningful. I noticed this on a filename that contained parentheses, but didn't add any error checking.
  • This script does not preserve aspect ratios, so if you feed it an image that's not square it will produce distortions. If you want to preserve aspect rations, keep in mind that icons have to be square, so you'll have to square the image by cropping or padding first.
Ted Wrigley
  • 2,921
  • 2
  • 7
  • 17
1

If you right click on an Application file in Finder and choose the option to “Show Package Contents” If you open its .icns file (usually located within the resources folder), using Preview app, Using the thumbnail view in the sidebar, you will notice that within the file, contains several versions of the same icon. Each one is of a different size and resolution (1024 x 1024 at 144 pixels per inch, 512 x 512 at 72 pixels per inch, etc…)

I'm pretty sure the system decides which version and size of the embedded icon will be used, depending on the situation. For example the icon size used in the Dock will be larger than the icon used for an opened adocument for the application while it is running.

enter image description here

If you're looking to just change the icon of an AppleScript applet using a .png file in the get info window in Finder. 256 x 256 at 72 pixels per inch should be fine.

wch1zpink
  • 3,026
  • 1
  • 8
  • 19
  • I have been searching for apps to convert from png to icns but I think, none of them are able to contain several versions of the img. Do you know any program to do that? I use Inkscape an Gimp and they cannot convert to ecns – Nrc Oct 01 '19 at 15:18
  • There are two commandline utilities you can use: `iconutil` and `tiff2icns`. The second merely converts a tiff file to a single-entry icns file; the second converts between .iconset objects (basically, folders of images) to .icns files. What I do is find a .icns file somewhere, convert it to and iconset, use the command-line tool `sips` or an image processing app to replace all of the images in the iconset with properly-sized versions of the image I was to use, then reconvert the icons back to an icns. I can write out a script to do it, I think. give me a bit, and check my answer below. – Ted Wrigley Oct 01 '19 at 15:48