A long time ago I published a tool called iTunesIcon that would grab an app icon from iTunes. It worked well in its time, but has been mostly broken in recent years. It was designed mostly for writers who were reviewing apps and needed to get an app’s icon for artwork, but could be used by anyone with a need for such things.
As part of automating the giveaways I’m running, I’ve had a need to start grabbing app icons again, so I’ve revived the project. This script requires installing ImageMagick for rounding the corners of iOS icons (brew install imagemagick
).
I previously had a shell function called geticonpng
that read a local app’s icon file. These days, most local Mac apps tend to store their icons in Assets.car archives, so the default .icns file only has images up to 256 pixels in most cases. I’ve worked around that. And when a local icon can’t be found, I’m falling back to searching iTunes, replicating the behavior of iTunesIcon. This script handles the following:
- Allow defining platform (mac, iOS, iPad, iPhone)
- Allow defining size (small, medium, large, or specific pixel dimensions)
- If the platform is Mac, test for a local copy from which to extract the icon
- If the platform is iOS or a local Mac app isn’t found, search iTunes and return the first result
- If the platform is Mac and a local version is found, extract the icon from the Assets file to allow higher resolutions
- If the platform is iOS, automatically round the corners and resize the image
Here’s the (Ruby) script. It handles all of the above.
Platform can be defined in two ways:
- Use the
-d DEVICE
flag when running the script. This can beios
,iphone
,ipad
, ormac
- Add a modifier to the search terms in the form of
@ios
,@iphone
,@ipad
, or@mac
, e.g.OmniFocus @ipad
Similarly, size can be defined using:
- Use the
-s SIZE
flag, which can bes(mall)
,m(edium)
, orl(arge)
or a specific pixel dimension (square), e.g.grabicon.rb -s small OmniFocus
- Use a modifier in the search terms in the form of
%s(mall)
,%m(edium)
,%l(arge)
or a specific pixel dimension, e.g.OmniFocus %1024
Modifiers in the search terms override flags given to the script.
If a local copy can be found, the asset will be extracted at any size specified. If searching iTunes, you’re generally limited to 1024px, depending on the assets the app has provided. The nearest icon format will be downloaded, and ImageMagick will convert to specific pixel dimensions. Note that when downloading an iOS icon, the artwork provided is square, so the script will round the corners and add 10% padding around the icon (using ImageMagick) to offer similar dimensions to what Mac icons have or what you see on your iOS device screen.
All options:
Usage: grabicon.rb 'APP NAME/SEARCH TERM' [@PLATFORM] [%SIZE]
@ and % modifiers override options
OPTIONS:
-p, --preview Show a Quick Look preview after saving
-s, --size SIZE Size to save (small, medium, large, or pixels)
-d, --device PLATFORM Platform to search (mac, ios, iphone, ipad)
-o, --output PATH Path to save icon to (default ~/Desktop/ICON.png)
-h, --help Display this screen
This is working well for me so far. I’ll publish the rest of the giveaway automation in the future, as it uses some ImageMagick commands I think might be useful to other people. But for now, this is the new iTunesIcon script.
To install the script, save the raw version to a file called grabicon.rb
in your PATH, and then run chmod a+x PATH/TO/grabicon.rb
. Once that’s done, just run grabicon.rb -h
to see available options.