// enable double clicking from the Macintosh Finder or the Windows Explorer #target photoshop // in case we double clicked the file app.bringToFront(); main(); function main() { if ( app.documents.length <= 0 ) { alert("You must have a document open to Save For Web"); return; } // Convert the Profile to sRGB app.activeDocument.convertProfile("sRGB IEC61966-2.1", Intent.RELATIVECOLORIMETRIC); // Run Save for web and fix the document state try { RunSaveForWeb(); PreviousState(); } catch (error) { if (error.number != 8007) // Don't report user cancelled errors. alert (error); // + ":" + error.line); } // This is a function that restores the document to the original profile // by stepping back a step in the history palette function PreviousState() { var id50 = charIDToTypeID( "slct" ); var desc7 = new ActionDescriptor(); var id51 = charIDToTypeID( "null" ); var ref1 = new ActionReference(); var id52 = charIDToTypeID( "HstS" ); var id53 = charIDToTypeID( "Ordn" ); var id54 = charIDToTypeID( "Prvs" ); ref1.putEnumerated( id52, id53, id54 ); desc7.putReference( id51, ref1 ); executeAction( id50, desc7, DialogModes.NO ); } // This is a function that calls the Save For Web Dialog function RunSaveForWeb() { var id637 = charIDToTypeID( "slct" ); var desc89 = new ActionDescriptor(); var id638 = charIDToTypeID( "null" ); var ref21 = new ActionReference(); var id639 = charIDToTypeID( "Mn " ); var id640 = charIDToTypeID( "MnIt" ); var id641 = charIDToTypeID( "Svfw" ); ref21.putEnumerated( id639, id640, id641 ); desc89.putReference( id638, ref21 ); executeAction( id637, desc89, DialogModes.NO ); } }