Programming Photoshop action?


Status
Not open for further replies.

tomshen

Senior Member
Feb 20, 2002
3,644
0
36
Singapore
#1
I checked PS online help but cannot get any clue. I want to know if I could add "if...then..." in PS actions. Like that I would be able to create a few actions and automate my entire workflow. Anyone has some idea?
 

oeyvind

Senior Member
Feb 25, 2002
3,828
1
38
www.oeyvind.org
#2
tomshen said:
I checked PS online help but cannot get any clue. I want to know if I could add "if...then..." in PS actions. Like that I would be able to create a few actions and automate my entire workflow. Anyone has some idea?
You can create/record your actions: i.e. record an action to run a series of actions, no problem on that-that's what I do anyway.

If you want more try this using Python:

http://opensource.adobe.com/project1/project.shtml

May break in anytime soon.

If you want the SDK, you need to join their developers program... pay money!

http://partners.adobe.com/asn/photoshop/index.jsp

If you know AppleScript, JavaScript or VB see:

http://partners.adobe.com/asn/photoshop/scripting.jsp
 

tomshen

Senior Member
Feb 20, 2002
3,644
0
36
Singapore
#4
wah, thx man! I am not talking about recording. I want to insert conditional statements in the action, like "if landscape mode, then do what; if square mode, then do what; etc". Have not used any SDK with PS. Let me see first.
 

StreetShooter

Senior Member
Jan 17, 2002
4,634
0
0
Katong
streetshooter.clubsnap.org
#5
What I would do is simply record different actions for different types of pictures, and assign function keys. Use your brain to carry out the if-then commands.

Alternatively just group the pictures into different directories, and batch process each directory differently.
 

tomshen

Senior Member
Feb 20, 2002
3,644
0
36
Singapore
#7
StreetShooter said:
What I would do is simply record different actions for different types of pictures, and assign function keys. Use your brain to carry out the if-then commands.

Alternatively just group the pictures into different directories, and batch process each directory differently.
I also do that, but I found it boring. I have to separate landscape photos from portrait photos, and apply different frame edge settings. I just want to use one action with "if...then..." to do the entire post-processing, including dispatch the images to achive, printing, and web folders properly.
 

tomshen

Senior Member
Feb 20, 2002
3,644
0
36
Singapore
#8
btw, if no need to add frame edge, then the "fit image" works very well, irregardless of whichever modes.
 

Royce

New Member
Aug 25, 2003
538
0
0
Singapore
www.roycelithgo.com
#9
StreetShooter said:
What I would do is simply record different actions for different types of pictures, and assign function keys. Use your brain to carry out the if-then commands.

Alternatively just group the pictures into different directories, and batch process each directory differently.
Exactly what I had to do... the different directories approach. Branching logic is not available in Actions.
 

oeyvind

Senior Member
Feb 25, 2002
3,828
1
38
www.oeyvind.org
#11
do share your script if you have one... to get it started here's my custom border script which I run part of my PS Action

Code:
/* 
  WEB Photo Border Script
   © 2004 Tim Chong [url]http://www.oeyvind.org/[/url]
   
   Last modified: 2004-03-17
   
   Purpose:
   	Create an outer and inner border, and run part of my PS action
   	to add a copyright message at bottom right for web images
   	
   Usage:
   	Access it from File:Scripts:[SCRIPT NAME]
   	
*/

// Variables

// extra space at bottom for copyright msg
bottomBorderThickness = 15;

// Outer black border settings
outerBorderThickness = 5; 					

// Inner white border settings
innerBorderThickness = 2;					

// End Variables

// BEGIN SCRIPT

if (app.documents.length > 0)
{    
	// Save old units and set to px
	oldUnits = app.preferences.rulerUnits;
	app.preferences.rulerUnits = Units.PIXELS;

	// Save old background color
	oldbgColor = app.backgroundColor;

	// add 2 px white inner border around doc
	var bgColor = new SolidColor;
	bgColor.rgb.red = 255;
	bgColor.rgb.green = 255;
	bgColor.rgb.blue = 255;
	app.backgroundColor = bgColor;

	docWidth = app.activeDocument.width + (innerBorderThickness*2);
	docHeight = app.activeDocument.height + (innerBorderThickness*2);
	app.activeDocument.resizeCanvas(newWidth, newHeight, AnchorPosition.MIDDLECENTER);

	// add 5 px black outer border around doc
	var bgColor = new SolidColor;
	bgColor.rgb.red = 0;
	bgColor.rgb.green = 0;
	bgColor.rgb.blue = 0;
	app.backgroundColor = bgColor;

	docWidth = app.activeDocument.width + (outerBorderThickness*2);
	docHeight = app.activeDocument.height + (outerBorderThickness*2);
	app.activeDocument.resizeCanvas(newWidth, newHeight, AnchorPosition.MIDDLECENTER);

	// add 15 px black outer border at bottom
	docHeight = app.activeDocument.height + (bottomBorderThickness);
	app.activeDocument.resizeCanvas(newWidth, newHeight, AnchorPosition.TOPCENTER);

	// reset 
	app.preferences.rulerUnits = oldUnits;
	app.backgroundColor = oldbgColor;
	
	// Clear up memory
	bottomBorderThickness = null;
	innerBorderThickness = null;
	outterBorderThickness = null;
	bgColor = null;
	docWidth = null;
	docHeight = null;
}
else
{
    alert("You must have at least one open document to run this script!");
}
// END OF SCRIPT
A copy of this script is also available, here
 

Jul 3, 2003
222
0
16
Singapore
Visit site
#13
Actually, if you are using Photoshop CS, there's an easier way to do it. Of course, it is not as efficient as if you were to write the whole thing from scratch but a good starting point. All you have to do is customize enough of it to do what you want it to do...

There's a built-in feature called the ScriptListener. This file is a .8li file and is resident on your c:\...\adobe\photoshop cs\scripting guide\utilities\. Copy this file to c:\...\adobe\photoshop cs\plug-ins\adobe photoshop only\automate.

After you do that, start Photoshop, bring up the Actions window. RECORD (not play) the actions you require, you can bring up other commands such as export etc., using the left arrow key on the Actions window. After you are done, there will be two new files called c:\scriptinglistenerjs.log and c:\scriptinglistenervb.log, which records all the actions you just performed. When you are done, remember to move the file back or the log will continue recording actions you play and record. If you batch process 200 files, you can imagine how big the log file will be...

Start a new text file, copy the relevant script over, replace the variables (Photoshop defaults are boring - ids and descs), add in the if...then, do...loop commands and you have your new script file.

In c:\...\adobe\photoshop cs\scripting guide\, there are Visual Basic and Javascript Reference Guides for Photoshop features...

Of course, I am no javascript expert (in fact, I am prefer Visual Basic to Javascript, but it is easy to screw up if one is to try to get Visual Basic to talk directly to Photoshop) and am learning as I go, so any additional tips after someone else experiments with the feature is most welcomed. I have also not figured out how to use automate the script for every picture file in a specific folder and to save as a different name convention a la the Batch feature on Photoshop...
 

oeyvind

Senior Member
Feb 25, 2002
3,828
1
38
www.oeyvind.org
#14
thx... need to RTFM more. :)

This make scripting much easier, now you need to just program in the logic... cool!

P.S. This works for Mac as well, just subsitute the path with the one on your mac. The resultant file will be created on your desktop instead of c:\
 

Status
Not open for further replies.
Top Bottom