I have a layered Photoshop tiff and each layer has a mask. I am trying to use the save for web command and it keeps telling me it can’t find current document. I have been able to do this same script with a save command and saving it as a png, but I find that way makes the file size a lot larger. So I really need the save for web.
For the life of me I cannot figure this out… :mad: maybe I have been staring at it too long. Any help would be great!
I marked in the code where I get the problem, it is towards the end of “photoshopProcessMoment”
Here is the code:
tell application "Finder"
set basePath to (path to desktop folder)
end tell
tell application "Adobe Photoshop CS6"
activate
set background color to {class:RGB color, red:255, green:255, blue:255}
my photoshopProcessMoment_(basePath, "_zm.png", 0, 0, 0)
end tell
on photoshopProcessMoment_(theLocation, imageType, setImageHeight, setCanvasHeight, setCanvasWidth)
--> put a 0 (zero) in the setImageHeight, setCanvasHeight, setCanvasWidth if you do not want to change the size of the image or canvas
tell application "Adobe Photoshop CS6"
set docref to current document
if setImageHeight ≠0 then
resize image docref height setImageHeight
end if
if setCanvasHeight ≠0 then
resize canvas docref height setCanvasHeight
end if
if setCanvasWidth ≠0 then
resize canvas docref width setCanvasWidth
end if
activate
make new art layer in current document with properties {visible:false}
set myLayers to count each layer in layer set 1 in current document
set properties of (layers 1 thru myLayers) in layer set 1 in current document to {visible:true}
set firstLayer to make new art layer in layer set 1 in current document with properties {visible:false}
set properties of layer 1 in layer set 1 in current document to {visible:true}
set properties of current layer in current document to {visible:true}
--return firstLayer
repeat (myLayers + 1) times
my duplicateLayer_()
set layerName to get properties of layer 1 in current document
-- this is the only way I could get the apply layer mask to work
if bounds of layerName ≠{0.0, 0.0, 0.0, 0.0} then
if bounds of layerName ≠{0.0, 0.0, 2000.0, 2000.0} then
if bounds of layerName ≠{0.0, 0.0, 272.0, 272.0} then
if bounds of layerName ≠{0.0, 0.0, 192.0, 192.0} then
if bounds of layerName ≠{-15.0, 0.0, 70.0, 85.0} then
if bounds of layerName ≠{0.0, 0.0, 75.0, 75.0} then
if bounds of layerName ≠{0.0, 0.0, 61.0, 61.0} then
if bounds of layerName ≠{-71.0, -13.0, 259.0, 317.0} then
if bounds of layerName ≠{-58.0, 0.0, 246.0, 304.0} then
my applyLayerMask_()
end if
end if
end if
end if
end if
end if
end if
end if
end if
set newName to characters 1 thru -5 of name of layerName
set newFilePath to (theLocation & newName & imageType) as string
set myOptions to {web format:PNG, transparency:true}
-- ¢¢¢¢ THIS IS WHERE IT TELLS ME IT CAN'T FIND THE DOCUMENT "UNTITLED-1" (WHICH IS THE NAME OF THE DOCUMENT) ¢¢¢¢
export docref in file newFilePath as save for web with options myOptions with copying
-------
close current document saving no
delete layer 1 in layer set 1 in current document
end repeat
end tell
end photoshopProcessMoment_
on duplicateLayer_()
tell application "Adobe Photoshop CS6"
do javascript "{var idMk = charIDToTypeID( \"Mk \" );
var desc15 = new ActionDescriptor();
var idnull = charIDToTypeID( \"null\" );
var ref12 = new ActionReference();
var idDcmn = charIDToTypeID( \"Dcmn\" );
ref12.putClass( idDcmn );
desc15.putReference( idnull, ref12 );
var idUsng = charIDToTypeID( \"Usng\" );
var ref13 = new ActionReference();
var idLyr = charIDToTypeID( \"Lyr \" );
var idOrdn = charIDToTypeID( \"Ordn\" );
var idTrgt = charIDToTypeID( \"Trgt\" );
ref13.putEnumerated( idLyr, idOrdn, idTrgt );
desc15.putReference( idUsng, ref13 );
executeAction( idMk, desc15, DialogModes.NO );}"
end tell
end duplicateLayer_
on applyLayerMask_()
-- does the photoshop command of applying the layer mask
tell application "Adobe Photoshop CS6"
do javascript "var idDlt = charIDToTypeID( \"Dlt \" );
var desc8 = new ActionDescriptor();
var idnull = charIDToTypeID( \"null\" );
var ref2 = new ActionReference();
var idChnl = charIDToTypeID( \"Chnl\" );
var idChnl = charIDToTypeID( \"Chnl\" );
var idMsk = charIDToTypeID( \"Msk \" );
ref2.putEnumerated( idChnl, idChnl, idMsk );
desc8.putReference( idnull, ref2 );
var idAply = charIDToTypeID( \"Aply\" );
desc8.putBoolean( idAply, true );
executeAction( idDlt, desc8, DialogModes.NO );"
end tell
end applyLayerMask_