Action Frustration

EG
Posted By
Eldor_Gemst
May 13, 2005
Views
1075
Replies
19
Status
Closed
I’m having a lot of trouble getting some actions working as I want, and wonder if anyone here would be able to help me… (CS2 by the way.)

My action does a lot of stuff and most of it’s working, but there are two snags:

First problem is that I want to move/copy my signature from one opened image to another. Manually, I’d just click on the image containing the signature, select all (CTRL-A) and then Shift-Drag (so that position is maintained – both images are the same size and orientation) the signature to the other image. The signature file contains only the signature, already sized and positioned where I want it to appear. I just haven’t been able to get this step working in an action, and I’ve tried both manually clicking on that other image and using the Window menu to select it. Just doesn’t happen, although the action does appear to run and indeed continues to next steps.

The second issue is that I want to do a "Save for Web", but with a twist. I want to make sure my resulting JPG file is optimzed to 140k and doing it manually always works. The problem with the action is that it seems to record a quality level rather than the 140k limit, meaning that if the image I used to record the action ended up being 82 percent quality, all the remaining images would be the same. And that gives me file sizes all across the map! I want the highest quality that can be produced while keeping it within the 140k limit. And of course depending on the image, that might mean 100% quality or even down as low as 60%.

Suggestions would be gratefully appreciated.

Thanks!

Eldor

How to Master Sharpening in Photoshop

Give your photos a professional finish with sharpening in Photoshop. Learn to enhance details, create contrast, and prepare your images for print, web, and social media.

Y
YrbkMgr
May 13, 2005
Eldor,

First, in regards to your signature, if you want to drag it over and have that recorded, caveat emptor. Actions with multiple images open depend on a "next image/previous image" step. That is driven by what document is active when you start the action.

A far better way to do this is to record your signature being typed (assuming it’s plain text and not a graphic) and placed. For images of varying dimensions, it is often useful to first set your image rulers to Percent. Then record the typing of your signature. You can then move it to where ever you want and it will be placed in that area as a relative percentage of the image size.

In addition, an alternative way to perform the above is to type your signature, then Select|All (with the text layer active) and then include Layer|Align to Selection: Bottom, Layer|Align to Selection: Left (for example) and then nudge or move it where you like in the image. Then you can stop recording that portion.

To avoid an exceptionally lengthy action, you can "nest" actions. So you could have your signature placement as it’s own action, and then call that action from your main action which does all of your editing tasks. I find this easier for organization as well as fine tuning certain routine tasks like placing a signature.

In regards to the issue with Save For Web and its optimization, I’m afraid you have found one of the limitations of using SFW in an action. There is no way that I know of around the issue. All of the applet’s specs are hard coded into the action, and in this case it is the quality level that is recorded.

Hope that helps some.

Peace,
Tony
AT
Apple_Tom
May 13, 2005
The first issue is easy. Ctrl-A the layer with the signature file, Ctrl-C, then mouse click on the other document. Ctrl-V and you signature is there. If you read your action commands, you will see that the command is "select Previous Document" so it doesn’t matter what the document is.

On issue two, save for web with a twist, you will need to use conditional actions in ImageReady. Hatch recorded a great tutorial on conditional actions that can be downloaded from <http://www.wz2k.co.uk/>

Jim
C
chrisjbirchall
May 13, 2005
I want to move/copy my signature from one opened image to another

In your action: include Open (signature) File. Select all. Copy. Close. Paste.

This leaves no danger of a misinterperated select next or select previous command due to another file being accidentally left open.

Chris.
Y
YrbkMgr
May 14, 2005
This leaves no danger of a misinterperated select next or select previous command due to another file being accidentally left open.

Provided that you are only working with two images at a time.
EG
Eldor_Gemst
May 14, 2005
Tony, thanks very much for your helpful comments.

About the signature problem, it’s really a graphic of my signature/logo rather than pure text. And someone else (Phil Wigglesworth on the Robgalbraith board) suggested I use the "place" command instead. I’m going to give that a try.

Good suggestion about making more, but smaller, actions and then nesting them. Thanks!

Thanks for pointing out the limitations of Save for Web… John Beardsworth (again on the Robgalbraith board) supplied a looping script that’ll get around it just fine. So there is a way, although not directly by recording the action using SFW.

Cheers!

Eldor
EG
Eldor_Gemst
May 14, 2005
Apple Tom/Jim,

It’s not as easy as you suggest. I’ve recorded exactly those steps and they’re there, but it simply doesn’t do it. No error or anything but the logo’s not in the resulting file. Putting a stop into the action and doing it manually works just fine.

Someone else (on the Robbalbraith board) suggested using Place instead, as that’s supposed to work without fail in an action. I’l give that a try.

Thanks for the link/pointer to the tutorial on conditional actions in ImageReady. I’ll go check that out.

Regards…

Eldor
EG
Eldor_Gemst
May 14, 2005
Thanks Chris. I’ll give that a try. But someone else suggested that the "Place" command was a better solution.

Cheers!

Eldor
Y
YrbkMgr
May 14, 2005
a looping script that’ll get around it just fine

Want to post a link to that?
DR
Danny Raphael
May 14, 2005
Tony: Link you requested (I was curious, too)…

< http://www.robgalbraith.com/ubbthreads/showflat.php?Cat=0&am p;Number=337071&an=0&page=0#337071>

John Beardsworth crafted a nifty JS function that a) determines optimal file size (hard coded in script) and b) "loops" (trying different Quality values) until the file size is <= the specified target file size. It’s not a true SFW (doesn’t strip off EXIF or have other baggage issues, e.g., file naming in batch), which is a plus. Said to work under CS, but untested in CS2.

From what I can tell one would call the script from the action in lieu of recording a Save as… (.jpg) or SFW command.

– – – – – – –

Eldor:

If you’ve not discovered it yet ImageReady and PS actions aren’t compatible, so if you take the IR path you’ll need to start over. Could be the IR incarnation of SFW will let you specify the optimal file size so you can get consistently sized images.

I’d never used the File > Place command, so I checked it out. Under PS7 if you sig/logo is in .eps, .ai, .pdp, .pdf format it looks like it has possibilities.

If your sig/logo file is in (say) .psd or .jpg format, doesn’t look like Place is an option (under PS7, anyway) unless you convert it to one of those formats. Perhaps the file options in CS2 go beyond .eps, .ai, .pdp, .pdf.

Re: Steps above didn’t help
* Logo file open
* Test (target file) open
* Start recording
* Select previous document
* Click on logo layer (if not already selected)
* Select > All
* Edit > Copy
* Click on target image (Select next document)
* Edit > Paste

….and the logo layer does not appear when you play the action, but it does if you manually perform the steps.

Is that corrct? If so, this might be a CS2 issue. Somewhere among all these threads I read about an CS2 issue regarding pasting from the clipboard. I’ll see if I can find it.

~Danny~

keywords: cs2 clipboard paste SFW javascript
DR
Danny Raphael
May 14, 2005
re:

…this might be a CS2 issue. Somewhere among all these threads I read about an CS2 issue regarding pasting from the clipboard. I’ll see if I can find it.

My mistake. That problem was related to Edit > Paste after a preceding Print Screen command. <http://www.adobeforums.com/cgi-bin/webx?128@@.3bb829a4>
Y
YrbkMgr
May 14, 2005
Thanks for the link Danny. Based on your description, it’s not something I’m particularly interested in, but interesting nonetheless.
EG
Eldor_Gemst
May 15, 2005
YrbkMgr,

Sure, I’m glad to post a link (but I thought that by saying it was on the RobGalbraith board it would have been VERY easy to find)…

< http://www.robgalbraith.com/ubbthreads/showflat.php?Cat=0&am p;Number=337071&an=0&page=0#337071>

Haven’t got it fully working yet the way I want, but it won’t be long now.

Cheers!

Eldor
EG
Eldor_Gemst
May 15, 2005
Hi Danny,

Thanks for your comments.

And you obviously know a heck of a lot more about this stuff than I do (and that’s really not hard! 🙂 ) but looking at John Beardsworth code I didn’t see how Save for Web was being used so was surprised at the outcome that the resulting file did NOT contain EXIF data. Maybe you’d take another look at that code? What might be throwing you (please forgive me, as I’m a total weenie with this) is the initial call to SaveAs… as far as I can see, it’s used ONLY to obtain a filename and nothing else.

Anyway, my goal is to produce the highest quality JPG image (even sacrificing EXIF data) within any given filesize. Which is why I wanted to use Save for Web. Too bad that automating the SfW results in saving the current quality percentage rather than the request to optimize for a given filesize.

Where I’m stuck currently btw, is in obtaining the name of the currently open image (that’s being processed). In my string I end up with something like "[document mytest]" (without the quote marks but with the square brackets) intead of just "mytest". I’m thinking of looping through that result looking for the space and then taking the substring from the space position +1 to the end. But there’s probably some built-in function that more easily (and cleanly) returns just the filename.

I’m planning on concatenating my hard-coded target path, followed by the filename followed by ".jpg".

Once I’ve got that working the next challenge will be to find a way to make this more generic, so that instead of hard-coding a target path or asking for the path each time the script was run (because I want to process a hundred files at a time) I could set things up from OUTSIDE my process making this useable for many different target directories.

This stuff is really cool… wish I knew more about it!

Cheers!

Eldor
Y
YrbkMgr
May 15, 2005
Sure, I’m glad to post a link (but I thought that by saying it was on the RobGalbraith board it would have been VERY easy to find)…

I’m not that bright.
DR
Danny Raphael
May 15, 2005
Eldor:

Like you I’ve got some programming background and can more-or-less follow JaveScript code, but very, very little experience actually writing JavaScript. It’s a lot like having been fluent in Spanish and taking on a new foreign language. Some of it you get and a lot looks like mumbo-jumbo.

Just so you know… PS7 is where JavaScript became an option (via a plugin). Then, with CS, scripting functionalty was "built in," but the scripting libraries were updated = scripts between PS 7 <–> CS were not always compatible. With the introduction of CS2 there appear to be a few glitches in that implementation, so be aware this isn’t always a smoothe ride.

Regarding the file name issue, parsing the string until you hit the first space would surely work. Is there a better way? I’m sure there is, but my ignorance just reared its ugly head.

Now that you have some almost working code, you might consider jumping over to the Scripting forum (6th link from the top of this forum), copy/paste the appropriate code snippet and solicit the advice of the JS gang, who definitely speak the language.

Hope this helps get you over the hump. My compliments on your tenacity.

~Danny~
EG
Eldor_Gemst
May 16, 2005
Danny, (any anyone else interested),

I’ve now got the script working to my satisfaction but I’m sure that experienced folks would laugh at how I’ve butchered the code and hacked things together.

My goal was to automate saving images for the web, giving me the absolute highest quality possible without exceeding a certain filesize. I use this script as part of a larger action which already has sized the image properly and set it to sRGB mode (and a whole lot of other stuff). I can run my routine in batch mode against all open images in PS, or select a bunch of images through Bridge and then process those. The routine’s a little slow, as I start by writing the JPG at 100% quality, and then if it’s larger than my target filesize (I needed 140k) I re-write it at 99% quality, and keep looping through this way (always reducing the quality by 1) until the size is acceptable. I wish there was a way to automate Save for Web with the "optimize for file size" but there just doesn’t seem to be a way.

The other thing I’m doing which I don’t like is that I am hard-coding the target directory for the resulting JPG. I can live with that for now, but it would be nice to make this more generic. I don’t want the script to stop and ask me for a target, as it would be run over and over (I regularly process 100 images at a time) and any setting of that directory needs to be outside the script. So in the meanwhile I’m using this:

—————–
// With great thanks to John Beardsworth for his help with this! var docRef = app.activeDocument;
var fname = docRef.name
fname = CorrectedFilename(fname);
var saveRef = "/d/photos/1d/c1pro/kayak/web-140k/" + fname; var targetFileSize = 143360

if(saveRef && targetFileSize)
{
var qual = 100;
// would be much faster with a larger qStep
var qStep = 1;
ExportSave(saveRef, qual)
//loop through reducing the quality until below the target while (qual>0)
{
qual = qual – qStep;
var fRef = new File( saveRef );
if (fRef.length > targetFileSize )
{
fRef.remove();
ExportSave(saveRef, qual);
}

if (fRef.length <= targetFileSize ) break; } } function CorrectedFilename(fname) { // get just the name of the current document, without extension fname = fname.substring(0,fname.length-4); // add the jpg extension return fname + ".jpg"; } function ExportSave(filename, percentage) { //Script Listener code to execute Save for Web var id18 = charIDToTypeID( "Expr" ); var desc5 = new ActionDescriptor(); var id19 = charIDToTypeID( "Usng" ); var desc6 = new ActionDescriptor(); var id27 = charIDToTypeID( "Qlty" ); desc6.putInteger( id27, percentage ); var id45 = charIDToTypeID( "In " ); desc6.putPath( id45, new File( filename ) ); var id46 = stringIDToTypeID( "SaveForWeb" ); desc5.putObject( id19, id46, desc6 ); executeAction( id18, desc5, DialogModes.NO ); }

(Sorry folks that the end of the code lost the formatting… I can’t see how to fix that here, but I’ve also posted the code properly formatted in the Photoshop message board section of Robgalbraith (link higher up in this thread). Hope it is of help to someone.)
EG
Eldor_Gemst
May 16, 2005
I’m STUCK again!!! GRIN

If I open one or several images first in PhotoShop, I can Automate|Batch run my action just fine. (The action does many things and ends up calling the above script and then closing the file.) No problems. But if I select one or more images in Bridge and then using Tools|PhotoShop|Batch to run the same action, when it gets to the call for the script, I get:

The command "Scripts" is not currently available

I just don’t get it. Shouldn’t it operate the same way whether I call it from Bridge or PS? After all, when you are in Bridge and select Tools|PhotoShop|Batch you end up in PhotoShop to select the batch action to perform.

Anyone have an idea what’s going on here?

Thanks.

Eldor
DR
Danny Raphael
May 17, 2005
re: Hacked the script until it worked
A+ on doing that… Well done, sir.

re: The command "Scripts" is not currently available when invoked from Bridge

That does seem odd… I don’t have CS2 yet, so I can only speculate. When I’ve seen that message before it was symtomatic of an invalid file path (the .js file was in a different [not the default] scripts folder) or a missing (or renamed) .js file.

A couple things to try…
* If you duplicate your action and remove the Script command from the duplicatet, does the modified action work when invoked via Bridge?
* Craft another action that calls one of the Adobe-provided scripts and see if you can get it to work under Bridge.

Must-have mockup pack for every graphic designer 🔥🔥🔥

Easy-to-use drag-n-drop Photoshop scene creator with more than 2800 items.

Related Discussion Topics

Nice and short text about related topics in discussion sections