Photoshop Save for Web

Hello -

Poking about for ages and still can’t find anything on this. All I want to do is save the current document for web, on the desktop as a JPG, with quality = 100.

I’ve discovered export options save for web, but there doesn’t appear to be anything on the internet anywhere as to the syntax of it - I’ve been trying for a while and failing miserably!

Any help gratefully appreciated.

Cheers,

Hamish

photoshop has recording features/ automations? you can just set that up it takes a couple of seconds, i had to do it once to change the brightness and size of a heap of small images.

I know about Automator - sadly I need to do it in Applescript, as this script is to be distributed around various people to archive print jobs, and I can’t make sure that the actions are installed on everyone’s machines.
I’m sure it must be possible somehow…?
Hamish

Hi Hamish,

what’s the difference to distribute an AppleScript or a Photoshop action? :wink:
In this case I would create a PS action and distribute it wrapped in an application bundle installer script

it was alittle tricky but here it is


tell application "Finder"
	set savefolder to "" & (path to current user folder) & "Desktop:"
end tell
tell application "Adobe Photoshop CS2"
	activate
	set theName to name of document 1
	set tid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to "."
	set theName to text item 1 of theName
	set AppleScript's text item delimiters to tid
	
	export document 1 in ("" & savefolder & theName & ".jpg") as save for web with options {transparency:false}
	
end tell

Save for Web has a HUGE bug in it that won’t allow you to change the file type to JPEG. Here are the parts of the solution you will need to set up a script to batch process files. You will have to fill in the rest but this is the subroutine that fixes the bug and how to use it in PhotoShop on your export line:


on compileAsOption(valStr)
	tell application "Adobe Photoshop CS2"
		run script "tell application \"Adobe Photoshop CS2\" to return {«class fltp»:" & valStr & "}"
	end tell
end compileAsOption

set PathToDesktop to path to the desktop as text

tell application "Adobe Photoshop CS2"
set myoptions1 to {class:save for web export options, optimized size:true, quality:100, with profile:false} & my compileAsOption("JPEG")
export current document in file (PathToDesktop & FileNameVariable & ".jpg") as save for web with options myoptions1
end tell

Model: G5 Tower (not Intel) - Script Editor ver 2.1.1
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

matt what was the problem with what I had posted ? while I don’t specify the as jpeg option it defeaults to jpg.

It does have a record feature of sorts, but it involves quiting Photoshop, moving a plugin into the plugins folder, relaunch Photoshop, do your thing, then quit Photoshop, unload the plugin.

The plugin is a “watcher” called “ScriptingListener.plugin” that runs the entire time it is loaded and dumps JavaScript to a file on your desktop. This JavaScript can be run via an AppleScript or embedded into a self-running script (like with FaceSpan).

For example, this dump from the ScriptListener opens a file and simply re-saves it in order to rebuild the little thumbnail icon in the Finder:


// =======================================================
var id20 = charIDToTypeID( "Mk  " );
    var desc3 = new ActionDescriptor();
    var id21 = charIDToTypeID( "null" );
        var ref1 = new ActionReference();
        var id22 = charIDToTypeID( "Lyr " );
        ref1.putClass( id22 );
    desc3.putReference( id21, ref1 );
    var id23 = charIDToTypeID( "Usng" );
        var desc4 = new ActionDescriptor();
        var id24 = charIDToTypeID( "Nm  " );
        desc4.putString( id24, "SCRIPT_TEMP" );
    var id25 = charIDToTypeID( "Lyr " );
    desc3.putObject( id23, id25, desc4 );
executeAction( id20, desc3, DialogModes.NO );

// =======================================================
var id26 = charIDToTypeID( "Dlt " );
    var desc5 = new ActionDescriptor();
    var id27 = charIDToTypeID( "null" );
        var ref2 = new ActionReference();
        var id28 = charIDToTypeID( "Lyr " );
        var id29 = charIDToTypeID( "Ordn" );
        var id30 = charIDToTypeID( "Trgt" );
        ref2.putEnumerated( id28, id29, id30 );
    desc5.putReference( id27, ref2 );
executeAction( id26, desc5, DialogModes.NO );

// =======================================================
var id31 = charIDToTypeID( "save" );
executeAction( id31, undefined, DialogModes.NO );

// =======================================================
var id32 = charIDToTypeID( "Cls " );
executeAction( id32, undefined, DialogModes.NO );

Actually when I did the initial capture I had to weed out some code I didn’t need because it captures literally everything you do, which was a tad overkill.

The code to execute this from AppleScript was:


		tell application "Adobe Photoshop CS2"
			open (path_to_fix as alias)
			
			--execute JavaScript control of Photoshop
			--acquired with ScriptingListener plugin per Adobe guidelines
			do javascript (script_location as alias)
		end tell

I.E. open a given file, use script on it…script includes the close of the file. I tried the “do javascript” with the entire script embedded in a string in AppleScript but it kept choking on the quotes used throughout (even when changed to single quotes) so in the end I had to keep the Javascript external to the AppleScript. Knowing what I know now, I wonder if fiddling with delimiters would allow the JavaScript to be inside the AppleScript?

Hope this helps…