Quantcast
Channel: Adobe Community : Popular Discussions - Photoshop Scripting
Viewing all 12244 articles
Browse latest View live

Is "cropAndStraighten();" with custom border around the images possible?

$
0
0

Hi,

I am scanning batches of Polaroid and Instax pictures and to have them cropped from the scanned file and saved separately, I am using the following script which I found on a GitHub site (An photoshop batch script for crop & straighten photo from Jeffrey Tranberry · GitHub):

 

// cropAndStraightenBatch.jsx // Copyright 2006-2008 // Written by Jeffrey Tranberry // Photoshop for Geeks Version 2.0 /* Description: This script demonstates how to batch process a folder of images using the crop and straighten command */ // enable double clicking from the // Macintosh Finder or the Windows Explorer #target photoshop // Make Photoshop the frontmost application // in case we double clicked the file app.bringToFront(); ///////////////////////// // SETUP ///////////////////////// // A list of file extensions to skip, keep them lower case gFilesToSkip = Array( "db", "xmp", "thm", "txt", "doc", "md0", "tb0", "adobebridgedb", "adobebridgedbt", "bc", "bct" ); ///////////////////////// // MAIN ///////////////////////// //Make sure there are no open documents if (app.documents.length > 0){   alert ("This script requires that there are no open documents to run."); }else{   // Pops open a dialog for the user to choose the folder of documents to process   var inputFolder = Folder.selectDialog("Select a folder of documents to process");   // Pops open a dialog for the user to set the output folder   var outputFolder = Folder.selectDialog("Select a folder for the output files");   // Open and process a folder of Images   OpenFolder(); } ///////////////////////// // FUNCTIONS ///////////////////////// // Given the a Folder of files, open the files and process them function OpenFolder() {         var filesOpened = 0;         var fileList = inputFolder.getFiles();         for ( var i = 0; i < fileList.length; i++ ) {           // Make sure all the files in the folder are compatible with PS                 if ( fileList[i] instanceof File && ! fileList[i].hidden && ! IsFileOneOfThese( fileList[i], gFilesToSkip )) {                         open( fileList[i] );                         filesOpened++;                                 /////////////////////////   // Put all your processing functions...   /////////////////////////   // Create a variable to store a reference to   // the currently active document, which in this   // case is the parent document we want to extract   // multiple scanned images from   var docRef = app.activeDocument;   // Run the cropAndStraighten function   // which will rusult in more than one open document   cropAndStraighten();   // Close the parent document we originally opened   docRef.close(SaveOptions.DONOTSAVECHANGES);   // Process all open documents until no documents   // are left open.   while (app.documents.length >=1){   /////////////////////////   // Put all your processing functions...   /////////////////////////   // Flatten the document in case the file type we want to save to requires a flat doc   app.activeDocument.flatten();   //Save as a JPEG to the outputFolder   var jpegOptions = new JPEGSaveOptions();   jpegOptions.quality = 10;   jpegOptions.embedColorProfile = false;   app.activeDocument.saveAs( File( outputFolder  + "/" + activeDocument.name + ".jpg"), jpegOptions, false);   // Close without saving   app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);   /////////////////////////   // ...in the area between these two comments.   /////////////////////////   }                  /////////////////////////   // ...in the area between these two comments.   /////////////////////////   }         }         return filesOpened; } // given a file name and a list of extensions // determine if this file is in the list of extensions function IsFileOneOfThese( inFileName, inArrayOfFileExtensions ) {   var lastDot = inFileName.toString().lastIndexOf( "." );   if ( lastDot == -1 ) {   return false;   }   var strLength = inFileName.toString().length;   var extension = inFileName.toString().substr( lastDot + 1, strLength - lastDot );   extension = extension.toLowerCase();   for (var i = 0; i < inArrayOfFileExtensions.length; i++ ) {   if ( extension == inArrayOfFileExtensions[i] ) {   return true;   }   }   return false; } // Crop and Straighten function created // using the ScriptingListener plug-in function cropAndStraighten(){   var id333 = stringIDToTypeID( "CropPhotosAuto0001" );   executeAction( id333, undefined, DialogModes.NO ); }

 

In the script, the cropAndStraighten(); function sometimes cuts off a bit much of the white border of the Polaroids/Instax pictures. That's why I would have to automatically set a border which should be respected when cropping the images.

 

Does anybody know how you can do that?

I have no idea of Photoshop scripting / functions... :-(

 

Thanks a lot for any help

 

(oh no, I don't know why but the beautifully inserted html is messed up when posting my question, sorry)


Place images to a specific spot in a template

$
0
0

I am trying to create an action that will drop images into a specific spot in another document and save it with a certain file name. After the first image is dropped in and saved, I want my next image to do the same and so on. I have all my images cropped to the correct ratio and being pulled from a folder on my desktop. I have my template open in Photoshop where I want my images from that folder to be dropped into. Is this possible?

 

Any help is greatly appreciated!!

 

Melissa

Read and write data to Excel using javascript..!

$
0
0

Hi Everyone!

 

I have one excel document named as Temp.xls which is contains filename and file path.

 

Now I need check that Excel file name with active document name, If match found we need to update the current path of active document to existing file path location.

 

Please suggest me if any other solution much appreciated.

 

yajiv

 

My code is :

 

UpdateExcel();
function UpdateExcel(){            var docRef=app.activeDocument;    var docPath=docRef.path;    var dname=docRef.name;            var f = docPath+"/Temp.xls";    var datafile = new File(f);    if (datafile.exists) {     datafile.open('a') ;    while (datafile.eof){        strLineIn = datafile.readln();        colorArray = strLineIn.split(",");        if (colorArray[1]!=""){            if(colorArray[1].match(dname)!=null){                colorArray[2]=docPath;            }        }    }
}
}

Photoshop javascript: Open files in all subfolders

$
0
0

Hi guys

 

I'm very new to javascript, and general Photoshop scripting. My script is coming on well, but I struggle working with files and folders. It's a lack of basic javascript knowledge, which I need to work on. Right now, I'm trying to expand the image open part of my script, so that it opens images regardless of whether they are in a subfolder or not.

 

You can see my input folder (C:/Input). I want to be able to throw files in there, some in folders, some not. Out of interest, my outputs will be combined into one output folder... that bit is fine.

 

 

var inFolder = new Folder("C:/Input")

if(inFolder != null){

var fileList = inFolder.getFiles(/\.(jpg|tif|psd|bmp|gif|png|)$/i);

}

for(var a = 0 ;a < fileList.length; a++)

{

var docRef = open(fileList[a]);

//do things here

}

 

Is there an easy way of expanding this to include files in subfolders? All advice greatly appreciated.

Thanks

David

Read and change specific words in a text layer

$
0
0

Hi

 

I have a text layer in Adobe Photoshop (it's a text-frame). Suppose I deffined it as a variable called "myText"... by using:

 

var myText = app.activeDocument.layers.getByName("dados"); 

 

In Adobe Illustrator, I can simply use the property: "words" in order to acess an array of all words in the text frame. I could declare anything like:

 

var countWords = myText.words;

 

And...after... I can acess the "countWords[1]", "countWords[2]".... to acess all individual words and personalize them.

 

Looking at Photoshop documentation I did not find similar property or object or instance... In "textItem" object there's no "paragraph" or "words" option that I can try.

 

Is there any way in Photoshop I can acess individual words in a text frame layer, so I could, for example, chance the color of this word...or increase the size of just this word?

 

Thank you very much for the help.

 

Gustavo.

Script Alert: "Sorry I could not process the following files" (Error Message using Image Processor)

$
0
0

I'm a seasoned Photoshop/Bridge CS5 user who recently upgraded to CS6.  In Bridge I just ran my first Image Processor batch, trying to convert a set of RAW .NEF files to .PSD files with a basic editing action I created applied to them.  Photoshop CS6 opens the files from Bridge and applies the actions, but then I get the "Script alert" error message "Sorry I could not process the following files" and a list of all of the files in the batch I was trying to run the script on.  The files all remain open and are saved on my hard drive in a folder created by the Image Processor script, but do not close unless I manually close them.  I never had this problem in CS5 where the image processor would apply the desired actions to the batch of photos one at a time, then save and close.  Thoughts on how I can fix this bug?

Transforms guides into lines

$
0
0

good morning

I'm new to this place

 

 

I would like to know if there is a way to transform the guides into lines

 

 

As in the case

 

 

thank you

 

Schermata 2017-07-20 alle 11.28.00.png

How to make friends with СС2018 and СС2015 when working with XML-files

$
0
0

Hello everybody.

in the CC 2015 to read the files I have a script, everything works well

function readXML (file) {//------------------------------------  try {    file = File(file) 
//    file.encoding = "UTF8";   
//    file.lineFeed = "unix";       file.open('r');    content = file.read();    file.close();    return new XML(content);  } catch (e) {    alert("" + e.message + "\n Error read from XML " + file );  }  return content;
};

function writeXML(file,xml) {//---------------------------------
  try {    file = File(file)      //  file.encoding = "UTF8";           file.open("w");    file.write(xml);    file.close();  } catch (e) {    alert("" + e.message + "\n Error write to XML " );  }  return true;
};

 

PS CC2018 read XML file (I control the information from the file by using Alert() ), but if I write to the file back, the file will be empty

If add rows 03,04,19 -  CC2018 worked. But CC2015 not read XML file


photoshop scripting output

$
0
0

Is there a console or log for output from script events?  I tried making a function, which executes an alert correctly, but doesn't create a new document.  I can't find any way to see if this syntax is wrong or the command is just outdated. 

 

In the code below, for example, I see the alert message, but no new document.  I don't see anyway to see what's wrong with it and I pulled that line straight from the photoshop scripting guide. 

 

var createDocument = function() {

    alert("creating new doc!");

    app.documents.add(2,4);

};

Script Alert: "Sorry I could not process the following files" (Error Message using Image Processor)

$
0
0

I'm a seasoned Photoshop/Bridge CS5 user who recently upgraded to CS6.  In Bridge I just ran my first Image Processor batch, trying to convert a set of RAW .NEF files to .PSD files with a basic editing action I created applied to them.  Photoshop CS6 opens the files from Bridge and applies the actions, but then I get the "Script alert" error message "Sorry I could not process the following files" and a list of all of the files in the batch I was trying to run the script on.  The files all remain open and are saved on my hard drive in a folder created by the Image Processor script, but do not close unless I manually close them.  I never had this problem in CS5 where the image processor would apply the desired actions to the batch of photos one at a time, then save and close.  Thoughts on how I can fix this bug?

Passing arguments to the jsx file from command line

$
0
0
Thanks for taking my question.

I am using the following to be able to run my script from the command line.In case you were wondering on why i would be doing this- i would need to invoke the javascript from a server side code(like java,php etc. in my case it is java)

"c:\Program Files\Adobe\Adobe Utilities\ExtendScript Toolkit\ExtendScript Toolkit.exe" "c:\path to script\myscript.jsx"

Anyways, i have been successful in running the myscript.jsx from the command line but i am not able to figure out how i could pass arguments to "myscript.jsx" from the command line, and be able to refer to these arguments within the script.

I have tried the following

"c:\Program Files\Adobe\Adobe Utilities\ExtendScript Toolkit\ExtendScript Toolkit.exe" "c:\path to script\myscript.jsx" "argument1" "argument2"

and tried to refer these arguments within the script using arguments[0] and arguments[1] . But looks like this does not work.

Any thoughts?????

How can I automate a batch crop and straighten function on single pics?

$
0
0
Here's my problem. I have to shoot thousands of pics of baseball cards. The cards are of varying sizes but they're rectangular in shape. I need to crop out the background (black velvet) and maybe straighten the images (depending on how close I can get the images straight when I shoot them)

PS has a nice command that will automatically crop and straighten pics that have been scanned. I've tried to run this command on my single pics and it works fine, except that I also get two additional crops/pics of stray hairs on the black background. I've also tried to make an action that I can turn into a batch or droplet and run on all the pics. I've not had much success. I'll end up with pics of stray hairs and not the card. I then have to go and manually delete the stray pics. Too much work.

Is there any way I can automate the process of cropping, straightening the pics then saving then new version?

Thanks

Open URL in browser via Photoshop

$
0
0

Is this possible? I don't need a clickable link for the user or anything, I just need the script to open a URL in the users default browser. How would I go about doing this?

Need help with event ID and class ID for notifier

$
0
0

I"m trying to add a script notifier to handle the event when the user places a smart object which they link to their cloud library.

PasteSmartObjectLibrary.png

 

This (I believe) is the relevant code which is generated when I performed this action

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

var idpast = charIDToTypeID( "past" );
  var desc11 = new ActionDescriptor();

  var idAntA = charIDToTypeID( "AntA" );

  desc11.putBoolean( idAntA, true );

  var idAs = charIDToTypeID( "As  " );

  var idsmartObject = stringIDToTypeID( "smartObject" );

  desc11.putClass( idAs, idsmartObject );

  var idpushToDesignLibraries = stringIDToTypeID("pushToDesignLibraries" );

  desc11.putBoolean( idpushToDesignLibraries, true );

  var idFTcs = charIDToTypeID( "FTcs" );

  var idQCSt = charIDToTypeID( "QCSt" );

  var idQcsa = charIDToTypeID( "Qcsa" );

  desc11.putEnumerated( idFTcs, idQCSt, idQcsa );

  var idOfst = charIDToTypeID( "Ofst" );

      var desc12 = new ActionDescriptor();

      var idHrzn = charIDToTypeID( "Hrzn" );

      var idRlt = charIDToTypeID( "#Rlt" );

      desc12.putUnitDouble( idHrzn, idRlt, 0.000000 );

      var idVrtc = charIDToTypeID( "Vrtc" );

      var idRlt = charIDToTypeID( "#Rlt" );

      desc12.putUnitDouble( idVrtc, idRlt, 0.000000 );

  var idOfst = charIDToTypeID( "Ofst" );

  desc11.putObject( idOfst, idOfst, desc12 );

executeAction(idpast, desc11, DialogModes.NO );

 

According to what I have read in the documentation, I need the event iD from the 'executeAction' line, which should be the variable "idpast" ("past"), and the class ID from the 'putObject' line, which is the variable "idOfst" ( "Ofst" )

 

I tried the following code, but the event does not trigger the script (eventFile is the file which contains the javascript code to run for this event):

 

app.notifiers.add("past", eventFile, "Ofst")

 

Can anyone help me to determine the correct EventID and ClassID for this event notifier?

Help with script to read specific XMP metadata in an image

$
0
0

I'm creating a script for Photoshop to read a specific XMP metadata field in the file info of an image. I'm trying to specifically read the data that is located under the <dc:subject> area. I want to access the data under dc: subject > rdf: Bag > rdf: li. Here's an example (as it would appear in Raw Data field under an image's file info):

 

<dc:subject>    <rdf:Bag>        <rdf:li>****DATA I NEED HERE****</rdf:li>    </rdf:Bag></dc:subject>

 

So far, I have a script that can read XMP metadata, but I can't access that specific line of data I showed in the above example. I commented line 43 -- that needs to be updated so it can read into the dc: subject data. I can currently access certain pieces of data in an image file. For example, using this code, if i run xmp.getProperty(XMPConst.NS_DC, "subject") through the console, I get a result back, but it's not the data I need. I figured if I used the same logic as I applied to line 43, it would give me the results I am looking for. Any ideas on how to access the data I'm looking for?

 

function loadXMPLibrary() {    if (!ExternalObject.AdobeXMPScript) {        try {            ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');        } catch (e) {            alert("Can't load XMP Script Library")            return false;        }    }    return true;
}


function unloadXMPLibrary() {
    if (ExternalObject.AdobeXMPScript) {        try {            ExternalObject.AdobeXMPScript.unloadXMPLibrary();            ExternalObject.AdobeXMPScript = undefined;        } catch (e) {            alert("Couldn't unload XMP Script Library")        }    }
}


function writeXMP(xmpData, xmpFile) {
    xmpFile.open('w', 'Text');    xmpFile.encoding = 'UTF-8'    xmpFile.write(xmpData)    xmpFile.close()
}


function showXMPMetadata() {
    var xmpLoad = loadXMPLibrary();    if (xmpLoad) {        var filepath = app.activeDocument.path + '/' + app.activeDocument.name;        var myFile = File(filepath);        xmpFile = new XMPFile(myFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ);        xmp = xmpFile.getXMP();        var myXmp = xmp.serialize();        xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY)        var skus = myXmp.getProperty(XMPConst.NS_RDF,"Bag"); //this needs to be updated        unloadXMPLibrary ();        return skus;    };
};

Script to open the Open Dialog Window

$
0
0

Hello everyone!

I'm new to scripting and this is probably an easy question but I'm trying to write a script that opens the Open Dialog Window. Basically I need to start the script in one active document, have the script open the Open Dialog (to let the user select another image) and then finish the script in the newly opened document. Every script I find is to open a specific file, but I need it to be User Selected through the Open Dialog of Photoshop.

 

I hope that makes sense! LOL. Any help would be greatly appreciated!

 

Thanks,

Bradi

What? ActionReference, charIDToTypeID, stringIDToTypeID

$
0
0

Hi,

 

I am newbie to photoshop scripting but I do have few years experience with Javascript. Looking for clarification as I can't figure out what is  going on here.

 

I was looking for solution how to get array of selected artLayers and layersSets. I found couple solutions on blogs and forums which works, but I can't figure out what that code actually does so may someone could explain it line by line or point me to normal documentation as I found http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/photoshop/pdfs/photoshop_scriptref_ js.pdf doesn't explain anything just gives list of available functions.

How ActionDescriptor, ActionReference works, how returned object by executeActionGet(ref) is structured and how Photoshop stores actions in memory.

 

var ref = new ActionReference();

var selectedLayers = [];

ref.putEnumerated( // Puts an enumeration type and ID into a reference along with the desired class for the reference.

     //why I do need use putEnumerated? what it gives?

     charIDToTypeID("Dcmn"), // document

     charIDToTypeID("Ordn"), // typeOrdinal - what is ordinal?

     charIDToTypeID("Trgt") //enumTarget - what?why?

)

 

var desc = executeActionGet(ref); // returns ActionDescriptor, how this object structure looks? how it was created?

desc = desc.getList( stringIDToTypeID( 'targetLayers' )); //returns ActionList, but what is targetLayers,who specified targetLayers? or it means it targets all layers?

 

for(var i=0;i<c;i++){

            try{              

               selectedLayers.push(  desc.getReference( i ).getIndex() );//gets action reference index in the ActionList

            }catch(e){

              // selectedLayers.push(  desc.getReference( i ).getIndex()+1 ); //I commented this out as I can't understand why it is used, if we failed for i, how I can be sure that we will not fail for i+1??

            }

}

 

If I understand correctly it gives me indexes of actions but not layers. Is that right? After this code I should somehow get artLayer+layersSets by using action indexes?

--------------------------

--------------------------My structure of layers and groups is

   Layer 4

Group4(1)

      Layer 3

   Group 3(1)

Group 2(1)

   Layer 2

Group 1(1)

Layer 5

Layer 1

 

and when I select all groups ant layers script above which should return array of selected layers/groups indexes returns me this - 1,2,4,5,8,9,10,12,13. As you can see it is missing some numbers so I assume this is not array of layers indexes.

 

 

Thank you!

 

Tomas

Action Manager (Script Listener) code converter script!

A script to run an action according to the file name

$
0
0

Dear All,

 

I hope someone can help.

 

I am looking at the following task: I have several .jpg files in a folder. Their names are something like "ADE-4LP.jpg" or "DBA-3P.jpg" or "EFC-1P.jpg"

 

I would like to open these files in Photoshop and then run actions according to their file names. So for example, if the file name has the -4LP ending, the action named "Create4LP" is triggered. If the name has the -3P ending, the action "Create3P" is triggered and so on.

 

Can this be done with a script ?

 

Thanks muchly !!

 

Felix

How to make friends with СС2018 and СС2015 when working with XML-files

$
0
0

Hello everybody.

in the CC 2015 to read the files I have a script, everything works well

function readXML (file) {//------------------------------------  try {    file = File(file) 
//    file.encoding = "UTF8";   
//    file.lineFeed = "unix";       file.open('r');    content = file.read();    file.close();    return new XML(content);  } catch (e) {    alert("" + e.message + "\n Error read from XML " + file );  }  return content;
};

function writeXML(file,xml) {//---------------------------------
  try {    file = File(file)      //  file.encoding = "UTF8";           file.open("w");    file.write(xml);    file.close();  } catch (e) {    alert("" + e.message + "\n Error write to XML " );  }  return true;
};

 

PS CC2018 read XML file (I control the information from the file by using Alert() ), but if I write to the file back, the file will be empty

If add rows 03,04,19 -  CC2018 worked. But CC2015 not read XML file

Viewing all 12244 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>