Skip to content

Instantly share code, notes, and snippets.

@ma11hew28
Created November 23, 2010 03:50
Show Gist options
  • Save ma11hew28/711203 to your computer and use it in GitHub Desktop.
Save ma11hew28/711203 to your computer and use it in GitHub Desktop.
Photoshop Script to Create iPhone Icons from iTunesArtwork
// 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
}
@marcgibert
Copy link

Taken from the manual Photoshop CS4 JavaScript Ref.pdf

Installing scripts
To install a JavaScript in the Scripts menu, place it in the Scripts folder (Photoshop CS4/Presets/Scripts). The names of the scripts in the Scripts folder, without the file name extension, will be displayed in the Scripts menu. Any number of scripts may be installed in the Scripts menu.
Scripts added to the Scripts folder while Adobe Photoshop CS4 is running will not appear in the Scripts menu until the next time you launch the application.
All scripts found in the Scripts folder and sub-folders are displayed at the top level of the File > Scripts menu. The addition of sub-folders does not add a hierarchical organization to the Scripts menu.

Executing other scripts
The Browse item at the end of the Scripts menu (File > Scripts > Browse) allows you to execute scripts which are not installed in the Scripts folder. You can also use Browse to select scripts installed in the Scripts folder after the application was last launched.
Selecting Browse displays a file browser dialog which allows you to select a script file for execution. Only .js or .jsx files are displayed in the browse dialog. When you select a script file, it is executed the same way as an installed script.

Startup scripts
On startup, Adobe Photoshop CS4 executes all .jsx files that it finds in the startup folders.
● On Windows, the startup folder for user-defined scripts is:
C:\Program Files\Common Files\Adobe\Startup Scripts CS4\Adobe Photoshop
● On Mac OS, the startup folder for user-defined scripts is:
~/Library/Application Support/Adobe/Startup Scripts CS4/Adobe Photoshop
If a script is meant to be executed only by Adobe Photoshop CS4, it must include code such as the following:
if( BridgeTalk.appName == "photoshop" ) { //continue executing script
}
For additional details, see the JavaScript Tools Guide CS4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment