• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How can I get this script/action to run?

Explorer ,
Nov 17, 2017 Nov 17, 2017

Copy link to clipboard

Copied

I've been using this script and action for years. Got a new Mac and now I get the attached error.

Here's the process:

  • Action that first deletes alpha channels,
  • Then un-does any clipping paths
  • Call this script (which has a specific file hierarchy it needs).
  • Then I get the attached error
  • Photoshop CC 2018 19.0
  • OS X 10.12.6

Any thoughts? Thanks!

Capto_Capture 2017-11-17_09-52-47_AM.png

// Pfade übernehmen v2.1

// Copyright Thamer Florian

// 30.11.2010

var docRef = app.activeDocument;

var docJPG= app.activeDocument;

// Check for a "TIF","PSD","JPG" Subdirectory, which contains the Images where the paths should be applied to.

var checksum = "0";

for( var i = "1"; i <= "3"; i++){

if( i == "1" ) {

var newpath = docRef.path + "/TIF/";

newpath = new File(newpath);

if(newpath.exists) {

checksum++;

var dateityp = "TIF";

}

}

if( i == "2" ) {

var newpath = docRef.path + "/PSD/";

newpath = new File(newpath);

if(newpath.exists) {

checksum++;

var dateityp = "PSD";

}

}

if( i == "3" ) {

var newpath = docRef.path + "/JPG/";

newpath = new File(newpath);

if(newpath.exists) {

checksum++;

var dateityp = "JPG";

}

}

}

if( checksum > "1") alert("Error! please create a single tif, psd or jpg subfolder"); // Error if there is more than one possible subdirectory

if( checksum < "1") alert("Error! No tif, psd or jpg subfolder available"); // Error if there is no possible subdirectory

if( checksum == "1") { // The Script will only run if there is exacly ONE compatible subdirectory

// open the TIF/PSD/JPG file with the same name as the JPG

var jpg = docRef.name;

var fname = docRef.name.split(".");

var fname1 = "";

for (var k = 0; k <= fname.length - 2; k++) {

fname1 = fname1 + fname + ".";

}

var fnamenew = fname1 + dateityp;

var newpath = docRef.path + "/" + dateityp + "/" + fnamenew;

var docRef = app.activeDocument;

var TIF = newpath;

// Opening the TIF/PSD/JPG file

var TIFShortcut = new File(TIF);

if( !TIFShortcut.exists ) {

alert("Oops! File " + TIFShortcut + " not found!" + jpg + " remains open"); // if the file does not exist stop scripts

}

else {

var docTIF = open(TIFShortcut);

// Check Resolution/Canvas size

app.activeDocument = docJPG;

if( docTIF.resolution != docJPG.resolution ) var sizeerr = "";

if( (docTIF.width != docJPG.width) || (docTIF.length != docJPG.length) ) var sizeerr = "";

if (sizeerr != null) {

alert("Document Size / Resolution different! \ NThe file" + jpg + " has a wrong document size / resolution. \  It will remain open");

docTIF.close();

}

else {

// Check color mode, color profile and bits per channel, and correct them

if( docTIF.mode != docJPG.mode ) docJPG.convertProfile(docTIF.colorProfileName, Intent.RELATIVECOLORIMETRIC, true, true);

if( docTIF.colorProfileName != docJPG.colorProfileName ) docJPG.colorProfileName = docTIF.colorProfileName;

if( docTIF.bitsPerChannel != docJPG.bitsPerChannel) docJPG.bitsPerChannel = docTIF.bitsPerChannel;

// So this is where i copy all the layers from the e.g. TIF to the JPG with paths

// I use the Select All Layers Command (cmd+alt+A - as far as i know not accessible through a menu)

// Problem is: It select all Layers EXCEPT the background layer

// So if there is a BG Layer i convert it to a normal layer first and rebackgroundize it afterwards.

app.activeDocument = docTIF;

var ebenen = docTIF.artLayers.length-"1";

if (docTIF.artLayers[ebenen].isBackgroundLayer == true) {

           docTIF.artLayers[ebenen].isBackgroundLayer = false;

           var hgset = "1";

}

// Select all layers

// =======================================================

var idselectAllLayers = stringIDToTypeID( "selectAllLayers" );

var desc14 = new ActionDescriptor();

var idnull = charIDToTypeID( "null" );

var ref8 = new ActionReference();

var idLyr = charIDToTypeID( "Lyr " );

var idOrdn = charIDToTypeID( "Ordn" );

var idTrgt = charIDToTypeID( "Trgt" );

ref8.putEnumerated( idLyr, idOrdn, idTrgt );

desc14.putReference( idnull, ref8 );

executeAction( idselectAllLayers, desc14, DialogModes.NO );

// DRAG all layers to the other document, this increases speed, cause nothing goes into clipboard

// and I don't copy layer by layer.

// =======================================================

var idDplc = charIDToTypeID( "Dplc" );

var desc50 = new ActionDescriptor();

var idnull = charIDToTypeID( "null" );

var ref40 = new ActionReference();

var idLyr = charIDToTypeID( "Lyr " );

var idOrdn = charIDToTypeID( "Ordn" );

var idTrgt = charIDToTypeID( "Trgt" );

ref40.putEnumerated( idLyr, idOrdn, idTrgt );

desc50.putReference( idnull, ref40 );

var idT = charIDToTypeID( "T   " );

var ref41 = new ActionReference();

var idDcmn = charIDToTypeID( "Dcmn" );

ref41.putName( idDcmn, jpg ); // jpg = target document

desc50.putReference( idT, ref41 );

var idVrsn = charIDToTypeID( "Vrsn" );

desc50.putInteger( idVrsn, 5 );

executeAction( idDplc, desc50, DialogModes.NO );

// close the original TIF/PSD/JPG file

docTIF.close(SaveOptions.DONOTSAVECHANGES);

// delete the layer from the JPG file that has been in Asia

var ebenen = docRef.artLayers.length-1;

docRef.artLayers[ebenen].remove();

// set the bottom layer as background if it was before

if (hgset) {

           var ebenen = docRef.artLayers.length-1;

           docJPG.artLayers[ebenen].isBackgroundLayer = true;

}

// and finally overwrite TIF/PSD/JPG in the TIF/PSD/JPG subdirectory

switch( dateityp ) {

case("TIF"): docRef.saveAs(new File(newpath),TiffSaveOptions); break;

case("PSD"): docRef.saveAs(new File(newpath),PhotoshopSaveOptions); break;

case("JPG"): docRef.saveAs(new File(newpath),JPEGSaveOptions); break;

}

docRef.close();

}

}

}

TOPICS
Actions and scripting

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Nov 17, 2017 Nov 17, 2017

Copy link to clipboard

Copied

Are yur sure this is the correct script?

Because the line #11 (with the error --> var theImage = app.activeDocument; ) doesn't exists in the script that you have posted.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 17, 2017 Nov 17, 2017

Copy link to clipboard

Copied

Yes, that was my fault. But, that was a good troubleshooting tip. It seems like, when I put the action calling the script in a file/automate/batch it has trouble finding an active document. Even though the batch should open a file and that should be the active document. Here's what I get now:

Capto_Capture 2017-11-17_12-01-22_PM.png

Does that make sense? Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 17, 2017 Nov 17, 2017

Copy link to clipboard

Copied

Make your script this way

try {

    app.bringToFront();

    // ...

    // put your original srcipt body here

    // ...

    }

catch(e) {  alert("Line: " + e.line + "\n\n" +  e, "Error", true);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 17, 2017 Nov 17, 2017

Copy link to clipboard

Copied

Hi, r-bin. Still the same error in the last screenshot. It does run fine if I have an active doc open in Photoshop, just not from a File/Automation/Batch with the attached settings. Thanks!

Capto_Capture 2017-11-17_01-12-27_PM.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 17, 2017 Nov 17, 2017

Copy link to clipboard

Copied

The alert should indicate the number of the line.

UPD,

There was an error in the previous post. Missing brackets

try {

    app.bringToFront();

    // ...

    // put your original srcipt body here

    // ...

    }

catch(e) {  alert("Line: " + e.line + "\n\n" +  e, "Error", true); }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 17, 2017 Nov 17, 2017

Copy link to clipboard

Copied

Thanks, r-bin, but same result. If I hit continue on the error when running, there are errors with numbers of the line but they refer again to not having an active doc. Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 17, 2017 Nov 17, 2017

Copy link to clipboard

Copied

I did not understand. Do you have at least one open document when the error occurs?

And further. Try in Bacth to change the Destination from "Save and close" to "None"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 20, 2017 Nov 20, 2017

Copy link to clipboard

Copied

I don't have any doc open when the error occurs. Tried batching both way but no success. Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 20, 2017 Nov 20, 2017

Copy link to clipboard

Copied

LATEST

But this means that the script has nothing to do with it. Most likely something is broken in your Actcion, which calls the script, and which for some reason closes the file before calling the script.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines