iOSアプリ用アイコンに一括リサイズするJavaScript for Automation

以前、

こういうのを作ったけど、その後iOS8が出て(ていうかiPhone 6 Plusが出て)、@3xの画像も生成しなきゃいけなくなったので作り直した。ついでに、もうすぐ大きいiPadが出てまた仕様が追加されるかも知れないので、今のうちからiPad用の@3xも生成するようにしてみた。

function openDocuments(docs) {
    var app = Application.currentApplication();
    app.includeStandardAdditions = true;

    var count = 0;
    for(var i = 0; i < docs.length; i++){
        var src = docs[i].toString();
        var path = src + '_icons';
        app.doShellScript('mkdir -p "' + path + '"');

        app.doShellScript('sips --resampleWidth   57 --out "' + path + '/Icon.png"             "' + src + '"'); //   57 x   57 for iPhone non-Retina -iOS6 App
        app.doShellScript('sips --resampleWidth  114 --out "' + path + '/Icon@2x.png"          "' + src + '"'); //  114 x  114 for iPhone Retina     -iOS6 App
        app.doShellScript('sips --resampleWidth   72 --out "' + path + '/Icon-72.png"          "' + src + '"'); //   72 x   72 for iPad   non-Retina -iOS6 App
        app.doShellScript('sips --resampleWidth  144 --out "' + path + '/Icon-72@2x.png"       "' + src + '"'); //  144 x  144 for iPad   Retina     -iOS6 App
        app.doShellScript('sips --resampleWidth   60 --out "' + path + '/Icon-60@.png"         "' + src + '"'); //   60 x   60 for iPhone non-Retina iOS7- App
        app.doShellScript('sips --resampleWidth  120 --out "' + path + '/Icon-60@2x.png"       "' + src + '"'); //  120 x  120 for iPhone Retina 2x  iOS7- App
        app.doShellScript('sips --resampleWidth  180 --out "' + path + '/Icon-60@3x.png"       "' + src + '"'); //  180 x  180 for iPhone Retina 3x  iOS7- App
        app.doShellScript('sips --resampleWidth   76 --out "' + path + '/Icon-76.png"          "' + src + '"'); //   76 x   76 for iPad   non-Retina iOS7- App
        app.doShellScript('sips --resampleWidth  152 --out "' + path + '/Icon-76@2x.png"       "' + src + '"'); //  152 x  152 for iPad   Retina 2x  iOS7- App
        app.doShellScript('sips --resampleWidth  228 --out "' + path + '/Icon-76@3x.png"       "' + src + '"'); //  228 x  228 for iPad   Retina 3x  iOS7- App
        app.doShellScript('sips --resampleWidth   29 --out "' + path + '/Icon-Small.png"       "' + src + '"'); //   29 x   29 for non-Retina -iOS6 Setting / Spotlight(iPhone)
        app.doShellScript('sips --resampleWidth   58 --out "' + path + '/Icon-Small@2x.png"    "' + src + '"'); //   58 x   58 for Retina 2x  -iOS6 Setting / Spotlight(iPhone)
        app.doShellScript('sips --resampleWidth   87 --out "' + path + '/Icon-Small@3x.png"    "' + src + '"'); //   87 x   98 for Retina 3x  -iOS6 Setting / Spotlight(iPhone)
        app.doShellScript('sips --resampleWidth   50 --out "' + path + '/Icon-Small-50.png"    "' + src + '"'); //   50 x   50 for non-Retina -iOS6 Spotlight(iPad)
        app.doShellScript('sips --resampleWidth  100 --out "' + path + '/Icon-Small-50@2x.png" "' + src + '"'); //  100 x  100 for Retina     -iOS6 Spotlight(iPad)
        app.doShellScript('sips --resampleWidth   40 --out "' + path + '/Icon-Small-40.png"    "' + src + '"'); //   40 x   40 for non-Retina iOS7- Setting / Spotlight
        app.doShellScript('sips --resampleWidth   80 --out "' + path + '/Icon-Small-40@2x.png" "' + src + '"'); //   80 x   80 for Retina 2x  iOS7- Setting / Spotlight
        app.doShellScript('sips --resampleWidth  120 --out "' + path + '/Icon-Small-40@3x.png" "' + src + '"'); //  120 x  120 for Retina 3x  iOS7- Setting / Spotlight
        app.doShellScript('sips --resampleWidth  512 --out "' + path + '/iTunesArtwork.png"    "' + src + '"'); //  512 x  512 for non-Retina App Store
        app.doShellScript('sips --resampleWidth 1024 --out "' + path + '/iTunesArtwork@2x.png" "' + src + '"'); // 1024 x 1024 for Retina     App Store
    }
}

以前はシェルスクリプトで書いたけど、10.10からはJavaScript for AutomationというのがあってJavaScriptMacスクリプティングができるので、今回はこっちにした。

上記のコードをOS X 10.10のスクリプトエディタにコピペして、アプリケーション形式で保存。そのappファイルのアイコンに好きな画像ファイルをドラッグすると動作する。複数の画像ファイルをまとめてドラッグしてもたぶん動く。

今のところ、最大のサイズは1024x1024なので、元画像はそれくらい、もしくはそれより大きく作るのがオススメ。

iTunesArtworkの@3xは無くていいのかな、よくわからない。

ていうかどんだけたくさん種類あるんだよ。。。まあそろそろiOS6は要らないかなーと思うけどね。