Skip to content

Instantly share code, notes, and snippets.

@C-EO
Forked from bugsysop/Create App Icons.jsx
Created August 16, 2021 19:46
Show Gist options
  • Select an option

  • Save C-EO/5f814dede214a5e47042750b19936e87 to your computer and use it in GitHub Desktop.

Select an option

Save C-EO/5f814dede214a5e47042750b19936e87 to your computer and use it in GitHub Desktop.

Revisions

  1. vigorouscoding revised this gist Feb 4, 2013. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Create App Icons.jsx
    Original file line number Diff line number Diff line change
    @@ -119,6 +119,7 @@ if (returnValue == 1) {

    // String check rather than using magic numbers
    if (platformOptions[destPlatform] == "iOS App") {
    sfw.transparency = false;
    icons = [
    {"name": "iTunesArtwork@2x", "size":1024},
    {"name": "iTunesArtwork", "size":512},
    @@ -132,6 +133,7 @@ if (returnValue == 1) {
    {"name": "Icon-Small-50@2x", "size":100}
    ];
    } else {
    sfw.transparency = true;
    icons = [
    {"name": "icon_16x16", "size":16},
    {"name": "icon_16x16@2x", "size":32},
  2. vigorouscoding revised this gist Feb 4, 2013. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions Create App Icons.jsx
    Original file line number Diff line number Diff line change
    @@ -81,8 +81,6 @@ dlg.center();
    var returnValue = dlg.show();

    if (returnValue == 1) {
    alert(platformOptions[destPlatform]);

    try {
    // Prompt user to select an image file. Clicking "Cancel" returns null.
    var iTunesArtwork = File.openDialog();
  3. vigorouscoding revised this gist Feb 4, 2013. 1 changed file with 122 additions and 94 deletions.
    216 changes: 122 additions & 94 deletions Create App Icons.jsx
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    // Photoshop Script to Create iPhone Icons from iTunesArtwork
    //
    // WARNING!!! In the rare case that there are name collisions, this script will
    // overwrite (delete perminently) files in the same folder in which the selected
    // overwrite (delete permanently) files in the same folder in which the selected
    // iTunesArtwork file is located. Therefore, to be safe, before running the
    // script, it's best to make sure the selected iTuensArtwork file is the only
    // file in its containing folder.
    @@ -52,102 +52,130 @@
    // Turn debugger on. 0 is off.
    // $.level = 1;

    try
    {
    // Prompt user to select iTunesArtwork file. Clicking "Cancel" returns null.
    var iTunesArtwork = File.openDialog("Select a sqaure PNG file that is at least 1024x1024.", "*.png", false);

    if (iTunesArtwork !== null)
    {
    var doc = open(iTunesArtwork, OpenDocumentType.PNG);

    if (doc == null)
    {
    throw "Something is wrong with the file. Make sure it's a valid PNG file.";
    }
    var dlg = new Window("dialog{text:'Create App Icons',bounds:[100,100,500,250],\
    warningText:StaticText{bounds:[25,80,380,200] , text:'* If the image is vector-based it can be smaller than 1024x1024, otherwise it is a really good idea for the file to be at least 1024x1024 pixels in size.' ,properties:{multiline:true}},\
    dropDownLabel:StaticText{bounds:[17,16,200,38] , text:'Create icons for' ,properties:{multiline:true}},\
    };");

    var startState = doc.activeHistoryState; // save for undo
    var initialPrefs = app.preferences.rulerUnits; // will restore at end
    app.preferences.rulerUnits = Units.PIXELS; // use pixels
    dlg.cancelBtn = dlg.add('button', [255,40,375,63], 'Abort', {name:'cancel'});
    dlg.selectImgBtn = dlg.add('button', [255,13,375,35], 'Select an image*', {name:'ok'});

    if (doc.width != doc.height)
    {
    throw "Image is not square";
    }
    else if ((doc.width < 1024) && (doc.height < 1024))
    {
    throw "Image is too small! Image must be at least 1024x1024 pixels.";
    }
    else if (doc.width < 1024)
    {
    throw "Image width is too small! Image width must be at least 1024 pixels.";
    }
    else if (doc.height < 1024)
    {
    throw "Image height is too small! Image height must be at least 1024 pixels.";
    }

    // Folder selection dialog
    var destFolder = Folder.selectDialog( "Choose an output folder");

    if (destFolder == null)
    {
    // User canceled, just exit
    throw "";
    }
    var platformOptions = [];
    platformOptions[0] = "iOS App";
    platformOptions[1] = "Mac App";

    // Save icons in PNG using Save for Web.
    var sfw = new ExportOptionsSaveForWeb();
    sfw.format = SaveDocumentType.PNG;
    sfw.PNG8 = false; // use PNG-24
    sfw.transparency = false;
    doc.info = null; // delete metadata

    var icons = [
    {"name": "iTunesArtwork@2x", "size":1024},
    {"name": "iTunesArtwork", "size":512},
    {"name": "Icon", "size":57},
    {"name": "Icon@2x", "size":114},
    {"name": "Icon-72", "size":72},
    {"name": "Icon-72@2x", "size":144},
    {"name": "Icon-Small", "size":29},
    {"name": "Icon-Small@2x", "size":58},
    {"name": "Icon-Small-50", "size":50},
    {"name": "Icon-Small-50@2x", "size":100}
    ];

    var icon;
    for (i = 0; i < icons.length; i++)
    {
    icon = icons[i];
    doc.resizeImage(icon.size, icon.size, // width, height
    null, ResampleMethod.BICUBICSHARPER);

    var destFileName = icon.name + ".png";

    if ((icon.name == "iTunesArtwork@2x") || (icon.name == "iTunesArtwork"))
    {
    // iTunesArtwork files don't have an extension
    destFileName = icon.name;
    }

    doc.exportDocument(new File(destFolder + "/" + destFileName), ExportType.SAVEFORWEB, sfw);
    doc.activeHistoryState = startState; // undo resize
    }
    dlg.dropdownlist = dlg.add("dropdownlist", [130,13,220,35]);

    alert("iOS Icons created!");
    }
    for (var i=0,len=platformOptions.length;i<len;i++) {
    dlg.dropdownlist.add ('item', "" + platformOptions[i]);
    }
    catch (exception)
    {
    // Show degbug message and then quit
    if ((exception != null) && (exception != ""))
    alert(exception);
    }
    finally
    {
    if (doc != null)
    doc.close(SaveOptions.DONOTSAVECHANGES);

    app.preferences.rulerUnits = initialPrefs; // restore prefs

    var destPlatform = 0;
    dlg.dropdownlist.selection = dlg.dropdownlist.items[destPlatform];

    dlg.dropdownlist.onChange = function() {
    destPlatform = parseInt(this.selection);
    }

    dlg.center();
    var returnValue = dlg.show();

    if (returnValue == 1) {
    alert(platformOptions[destPlatform]);

    try {
    // Prompt user to select an image file. Clicking "Cancel" returns null.
    var iTunesArtwork = File.openDialog();

    if (iTunesArtwork !== null) {
    var doc = open(iTunesArtwork);

    if (doc == null) {
    throw "Something is wrong with the file. Make sure it's a valid PNG file.";
    }

    var startState = doc.activeHistoryState; // save for undo
    var initialPrefs = app.preferences.rulerUnits; // will restore at end
    app.preferences.rulerUnits = Units.PIXELS; // use pixels

    if (doc.width != doc.height) {
    throw "Image is not square";
    }

    // Folder selection dialog
    var destFolder = Folder.selectDialog( "Choose an output folder");

    if (destFolder == null) {
    // User canceled, just exit
    throw "";
    }

    // Save icons in PNG using Save for Web.
    var sfw = new ExportOptionsSaveForWeb();
    sfw.format = SaveDocumentType.PNG;
    sfw.PNG8 = false; // use PNG-24
    sfw.transparency = false;
    doc.info = null; // delete metadata

    var icons;

    // String check rather than using magic numbers
    if (platformOptions[destPlatform] == "iOS App") {
    icons = [
    {"name": "iTunesArtwork@2x", "size":1024},
    {"name": "iTunesArtwork", "size":512},
    {"name": "Icon", "size":57},
    {"name": "Icon@2x", "size":114},
    {"name": "Icon-72", "size":72},
    {"name": "Icon-72@2x", "size":144},
    {"name": "Icon-Small", "size":29},
    {"name": "Icon-Small@2x", "size":58},
    {"name": "Icon-Small-50", "size":50},
    {"name": "Icon-Small-50@2x", "size":100}
    ];
    } else {
    icons = [
    {"name": "icon_16x16", "size":16},
    {"name": "icon_16x16@2x", "size":32},
    {"name": "icon_32x32", "size":32},
    {"name": "icon_32x32@2x", "size":64},
    {"name": "icon_128x128", "size":128},
    {"name": "icon_128x128@2x", "size":256},
    {"name": "icon_256x256", "size":256},
    {"name": "icon_256x256@2x", "size":512},
    {"name": "icon_512x512", "size":512},
    {"name": "icon_512x512@2x", "size":1024},
    ];
    }

    var icon;
    for (i = 0; i < icons.length; i++) {
    icon = icons[i];
    doc.resizeImage(icon.size, icon.size, null, ResampleMethod.BICUBICSHARPER);

    var destFileName = icon.name + ".png";

    if ((icon.name == "iTunesArtwork@2x") || (icon.name == "iTunesArtwork")) {
    // iTunesArtwork files don't have an extension
    destFileName = icon.name;
    }

    doc.exportDocument(new File(destFolder + "/" + destFileName), ExportType.SAVEFORWEB, sfw);
    doc.activeHistoryState = startState; // undo resize
    }

    alert(platformOptions[destPlatform] + " icons created!");
    }
    } catch (exception) {
    // Show degbug message and then quit
    if ((exception != null) && (exception != "")) {
    alert(exception);
    }
    } finally {
    if (doc != null) {
    doc.close(SaveOptions.DONOTSAVECHANGES);
    }

    app.preferences.rulerUnits = initialPrefs; // restore prefs
    }
    }
  4. vigorouscoding renamed this gist Feb 4, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. @twonjosh twonjosh revised this gist Sep 16, 2012. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions Create iOS Icons.jsx
    Original file line number Diff line number Diff line change
    @@ -66,6 +66,10 @@ try
    throw "Something is wrong with the file. Make sure it's a valid PNG file.";
    }

    var startState = doc.activeHistoryState; // save for undo
    var initialPrefs = app.preferences.rulerUnits; // will restore at end
    app.preferences.rulerUnits = Units.PIXELS; // use pixels

    if (doc.width != doc.height)
    {
    throw "Image is not square";
    @@ -92,10 +96,6 @@ try
    throw "";
    }

    var startState = doc.activeHistoryState; // save for undo
    var initialPrefs = app.preferences.rulerUnits; // will restore at end
    app.preferences.rulerUnits = Units.PIXELS; // use pixels

    // Save icons in PNG using Save for Web.
    var sfw = new ExportOptionsSaveForWeb();
    sfw.format = SaveDocumentType.PNG;
  6. @twonjosh twonjosh revised this gist Sep 9, 2012. 1 changed file with 10 additions and 2 deletions.
    12 changes: 10 additions & 2 deletions Create iOS Icons.jsx
    Original file line number Diff line number Diff line change
    @@ -122,8 +122,16 @@ try
    icon = icons[i];
    doc.resizeImage(icon.size, icon.size, // width, height
    null, ResampleMethod.BICUBICSHARPER);
    doc.exportDocument(new File(destFolder + "/" + icon.name + ".png"), ExportType.SAVEFORWEB, sfw);
    // doc.saveAs(new File(doc.path + "/" + icon.name + ".png"), new PNGSaveOptions());

    var destFileName = icon.name + ".png";

    if ((icon.name == "iTunesArtwork@2x") || (icon.name == "iTunesArtwork"))
    {
    // iTunesArtwork files don't have an extension
    destFileName = icon.name;
    }

    doc.exportDocument(new File(destFolder + "/" + destFileName), ExportType.SAVEFORWEB, sfw);
    doc.activeHistoryState = startState; // undo resize
    }

  7. @twonjosh twonjosh revised this gist Sep 8, 2012. 2 changed files with 145 additions and 91 deletions.
    91 changes: 0 additions & 91 deletions Create Icons.jsx
    Original file line number Diff line number Diff line change
    @@ -1,91 +0,0 @@
    // Photoshop Script to Create iPhone Icons from iTunesArtwork
    //
    // WARNING!!! In the rare case that there are name collisions, this script will
    // overwrite (delete perminently) files in the same folder in which the selected
    // iTunesArtwork file is located. Therefore, to be safe, before running the
    // script, it's best to make sure the selected iTuensArtwork file is the only
    // file in its containing folder.
    //
    // Copyright (c) 2010 Matt Di Pasquale
    //
    // Permission is hereby granted, free of charge, to any person obtaining a copy
    // of this software and associated documentation files (the "Software"), to deal
    // in the Software without restriction, including without limitation the rights
    // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    // copies of the Software, and to permit persons to whom the Software is
    // furnished to do so, subject to the following conditions:
    //
    // The above copyright notice and this permission notice shall be included in
    // all copies or substantial portions of the Software.
    //
    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    // THE SOFTWARE.
    //
    // Prerequisite:
    // First, create a 512x512 px PNG file named iTunesArtwork, according to:
    // http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/BuildTimeConfiguration/BuildTimeConfiguration.html
    //
    // Install - Save Create Icons.jsx to:
    // Win: C:\Program Files\Adobe\Adobe Utilities\ExtendScript Toolkit CS5\SDK
    // Mac: /Applications/Utilities/Adobe Utilities/ExtendScript Toolkit CS5/SDK
    // * Restart Photoshop
    //
    // Update:
    // * Just modify & save, no need to resart Photoshop once it's installed.
    //
    // Run:
    // * With Photoshop open, select File > Scripts > Create Icons
    // * When prompted select the prepared iTunesArtwork file for your app.
    // * The different version of the icons will get saved to the same folder that
    // the iTunesArtwork file is in.
    //
    // Adobe Photoshop JavaScript Reference
    // http://www.adobe.com/devnet/photoshop/scripting.html


    // Turn debugger on. 0 is off.
    // $.level = 1;

    // Prompt user to select iTunesArtwork file.
    var iTunesArtwork = File.openDialog("Select the iTunesArtwork file.");
    if (iTunesArtwork !== null) { // clicking "Cancel" returns null
    var doc = open(iTunesArtwork, OpenDocumentType.PNG);
    var startState = doc.activeHistoryState; // save for undo
    var initialPrefs = app.preferences.rulerUnits; // will restore at end
    app.preferences.rulerUnits = Units.PIXELS; // use pixels

    // Save icons in PNG using Save for Web.
    var sfw = new ExportOptionsSaveForWeb();
    sfw.format = SaveDocumentType.PNG;
    sfw.PNG8 = false; // use PNG-24
    sfw.transparency = false;
    doc.info = null; // delete metadata

    var icons = [
    {"name": "Icon", "size":57},
    {"name": "Icon@2x", "size":114},
    {"name": "Icon-72", "size":72},
    {"name": "Icon-Small", "size":29},
    {"name": "Icon-Small@2x", "size":58},
    {"name": "Icon-Small-50", "size":50}
    ];

    var icon;
    for (i = 0; i < icons.length; i++) {
    icon = icons[i];
    doc.resizeImage(icon.size, icon.size, // width, height
    null, ResampleMethod.BICUBICSHARPER);
    doc.exportDocument(new File(doc.path + "/" + icon.name + ".png"), ExportType.SAVEFORWEB, sfw);
    // doc.saveAs(new File(doc.path + "/" + icon.name + ".png"), new PNGSaveOptions());
    doc.activeHistoryState = startState; // undo resize
    }

    doc.close(SaveOptions.DONOTSAVECHANGES);

    app.preferences.rulerUnits = initialPrefs; // restore prefs
    }
    145 changes: 145 additions & 0 deletions Create iOS Icons.jsx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,145 @@
    // Photoshop Script to Create iPhone Icons from iTunesArtwork
    //
    // WARNING!!! In the rare case that there are name collisions, this script will
    // overwrite (delete perminently) files in the same folder in which the selected
    // iTunesArtwork file is located. Therefore, to be safe, before running the
    // script, it's best to make sure the selected iTuensArtwork file is the only
    // file in its containing folder.
    //
    // Copyright (c) 2010 Matt Di Pasquale
    // Added tweaks Copyright (c) 2012 by Josh Jones http://www.appsbynight.com
    //
    // Permission is hereby granted, free of charge, to any person obtaining a copy
    // of this software and associated documentation files (the "Software"), to deal
    // in the Software without restriction, including without limitation the rights
    // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    // copies of the Software, and to permit persons to whom the Software is
    // furnished to do so, subject to the following conditions:
    //
    // The above copyright notice and this permission notice shall be included in
    // all copies or substantial portions of the Software.
    //
    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    // THE SOFTWARE.
    //
    // Prerequisite:
    // First, create at least a 1024x1024 px PNG file according to:
    // http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/BuildTimeConfiguration/BuildTimeConfiguration.html
    //
    // Install - Save Create Icons.jsx to:
    // Win: C:\Program Files\Adobe\Adobe Utilities\ExtendScript Toolkit CS5\SDK
    // Mac: /Applications/Utilities/Adobe Utilities/ExtendScript Toolkit CS5/SDK
    // * Restart Photoshop
    //
    // Update:
    // * Just modify & save, no need to resart Photoshop once it's installed.
    //
    // Run:
    // * With Photoshop open, select File > Scripts > Create Icons
    // * When prompted select the prepared iTunesArtwork file for your app.
    // * The different version of the icons will get saved to the same folder that
    // the iTunesArtwork file is in.
    //
    // Adobe Photoshop JavaScript Reference
    // http://www.adobe.com/devnet/photoshop/scripting.html


    // Turn debugger on. 0 is off.
    // $.level = 1;

    try
    {
    // Prompt user to select iTunesArtwork file. Clicking "Cancel" returns null.
    var iTunesArtwork = File.openDialog("Select a sqaure PNG file that is at least 1024x1024.", "*.png", false);

    if (iTunesArtwork !== null)
    {
    var doc = open(iTunesArtwork, OpenDocumentType.PNG);

    if (doc == null)
    {
    throw "Something is wrong with the file. Make sure it's a valid PNG file.";
    }

    if (doc.width != doc.height)
    {
    throw "Image is not square";
    }
    else if ((doc.width < 1024) && (doc.height < 1024))
    {
    throw "Image is too small! Image must be at least 1024x1024 pixels.";
    }
    else if (doc.width < 1024)
    {
    throw "Image width is too small! Image width must be at least 1024 pixels.";
    }
    else if (doc.height < 1024)
    {
    throw "Image height is too small! Image height must be at least 1024 pixels.";
    }

    // Folder selection dialog
    var destFolder = Folder.selectDialog( "Choose an output folder");

    if (destFolder == null)
    {
    // User canceled, just exit
    throw "";
    }

    var startState = doc.activeHistoryState; // save for undo
    var initialPrefs = app.preferences.rulerUnits; // will restore at end
    app.preferences.rulerUnits = Units.PIXELS; // use pixels

    // Save icons in PNG using Save for Web.
    var sfw = new ExportOptionsSaveForWeb();
    sfw.format = SaveDocumentType.PNG;
    sfw.PNG8 = false; // use PNG-24
    sfw.transparency = false;
    doc.info = null; // delete metadata

    var icons = [
    {"name": "iTunesArtwork@2x", "size":1024},
    {"name": "iTunesArtwork", "size":512},
    {"name": "Icon", "size":57},
    {"name": "Icon@2x", "size":114},
    {"name": "Icon-72", "size":72},
    {"name": "Icon-72@2x", "size":144},
    {"name": "Icon-Small", "size":29},
    {"name": "Icon-Small@2x", "size":58},
    {"name": "Icon-Small-50", "size":50},
    {"name": "Icon-Small-50@2x", "size":100}
    ];

    var icon;
    for (i = 0; i < icons.length; i++)
    {
    icon = icons[i];
    doc.resizeImage(icon.size, icon.size, // width, height
    null, ResampleMethod.BICUBICSHARPER);
    doc.exportDocument(new File(destFolder + "/" + icon.name + ".png"), ExportType.SAVEFORWEB, sfw);
    // doc.saveAs(new File(doc.path + "/" + icon.name + ".png"), new PNGSaveOptions());
    doc.activeHistoryState = startState; // undo resize
    }

    alert("iOS Icons created!");
    }
    }
    catch (exception)
    {
    // Show degbug message and then quit
    if ((exception != null) && (exception != ""))
    alert(exception);
    }
    finally
    {
    if (doc != null)
    doc.close(SaveOptions.DONOTSAVECHANGES);

    app.preferences.rulerUnits = initialPrefs; // restore prefs
    }
  8. @ma11hew28 ma11hew28 revised this gist Nov 23, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Create Icons.jsx
    Original file line number Diff line number Diff line change
    @@ -73,7 +73,7 @@ if (iTunesArtwork !== null) { // clicking "Cancel" returns null
    {"name": "Icon-Small", "size":29},
    {"name": "Icon-Small@2x", "size":58},
    {"name": "Icon-Small-50", "size":50}
    ]
    ];

    var icon;
    for (i = 0; i < icons.length; i++) {
  9. @ma11hew28 ma11hew28 created this gist Nov 23, 2010.
    91 changes: 91 additions & 0 deletions Create Icons.jsx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,91 @@
    // Photoshop Script to Create iPhone Icons from iTunesArtwork
    //
    // WARNING!!! In the rare case that there are name collisions, this script will
    // overwrite (delete perminently) files in the same folder in which the selected
    // iTunesArtwork file is located. Therefore, to be safe, before running the
    // script, it's best to make sure the selected iTuensArtwork file is the only
    // file in its containing folder.
    //
    // Copyright (c) 2010 Matt Di Pasquale
    //
    // Permission is hereby granted, free of charge, to any person obtaining a copy
    // of this software and associated documentation files (the "Software"), to deal
    // in the Software without restriction, including without limitation the rights
    // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    // copies of the Software, and to permit persons to whom the Software is
    // furnished to do so, subject to the following conditions:
    //
    // The above copyright notice and this permission notice shall be included in
    // all copies or substantial portions of the Software.
    //
    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    // THE SOFTWARE.
    //
    // Prerequisite:
    // First, create a 512x512 px PNG file named iTunesArtwork, according to:
    // http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/BuildTimeConfiguration/BuildTimeConfiguration.html
    //
    // Install - Save Create Icons.jsx to:
    // Win: C:\Program Files\Adobe\Adobe Utilities\ExtendScript Toolkit CS5\SDK
    // Mac: /Applications/Utilities/Adobe Utilities/ExtendScript Toolkit CS5/SDK
    // * Restart Photoshop
    //
    // Update:
    // * Just modify & save, no need to resart Photoshop once it's installed.
    //
    // Run:
    // * With Photoshop open, select File > Scripts > Create Icons
    // * When prompted select the prepared iTunesArtwork file for your app.
    // * The different version of the icons will get saved to the same folder that
    // the iTunesArtwork file is in.
    //
    // Adobe Photoshop JavaScript Reference
    // http://www.adobe.com/devnet/photoshop/scripting.html


    // Turn debugger on. 0 is off.
    // $.level = 1;

    // Prompt user to select iTunesArtwork file.
    var iTunesArtwork = File.openDialog("Select the iTunesArtwork file.");
    if (iTunesArtwork !== null) { // clicking "Cancel" returns null
    var doc = open(iTunesArtwork, OpenDocumentType.PNG);
    var startState = doc.activeHistoryState; // save for undo
    var initialPrefs = app.preferences.rulerUnits; // will restore at end
    app.preferences.rulerUnits = Units.PIXELS; // use pixels

    // Save icons in PNG using Save for Web.
    var sfw = new ExportOptionsSaveForWeb();
    sfw.format = SaveDocumentType.PNG;
    sfw.PNG8 = false; // use PNG-24
    sfw.transparency = false;
    doc.info = null; // delete metadata

    var icons = [
    {"name": "Icon", "size":57},
    {"name": "Icon@2x", "size":114},
    {"name": "Icon-72", "size":72},
    {"name": "Icon-Small", "size":29},
    {"name": "Icon-Small@2x", "size":58},
    {"name": "Icon-Small-50", "size":50}
    ]

    var icon;
    for (i = 0; i < icons.length; i++) {
    icon = icons[i];
    doc.resizeImage(icon.size, icon.size, // width, height
    null, ResampleMethod.BICUBICSHARPER);
    doc.exportDocument(new File(doc.path + "/" + icon.name + ".png"), ExportType.SAVEFORWEB, sfw);
    // doc.saveAs(new File(doc.path + "/" + icon.name + ".png"), new PNGSaveOptions());
    doc.activeHistoryState = startState; // undo resize
    }

    doc.close(SaveOptions.DONOTSAVECHANGES);

    app.preferences.rulerUnits = initialPrefs; // restore prefs
    }