How to save a jpg and give it a label automatically

PS
Posted By
P_Shopper
Oct 20, 2008
Views
701
Replies
16
Status
Closed
Hi guys. I’ve found myself regularly repeating a set of actions and I was wondering if there was some way of automating them using CS4. The scenario is that I use Bridge as my main photo organisation app. I rate my shots from 1-5 stars and then tend to double click on ones to edit them in PS. After saving the edited shot as a jpg with "_edited" added to the filename, I apply a label which is called ‘Enhanced’ and then apply a ‘Original’ label to the original jpg. This lets me immediately filter of my edited/enhanced shots in Bridge and locate the originals if I need them. It also makes the edited files stand out when looked at in a file view of Explorer etc .

Is there an action or script I can create so that when I’ve finished editing a jpg it will take the original file name, add "_edited", save it as quality 10, baseline optimised, then apply the ‘Optimised’ label to the new file and exit the original jpg without saving but with applying the ‘Original" label?

Any advice would be much appreciated. Thanks.

Must-have mockup pack for every graphic designer ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ

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

PS
P_Shopper
Oct 21, 2008
I’ve been playing with ‘File, File Info, RAW Data’ and tried exporting, stippping down and re-importing the following XML to just contain the change I want to apply to other files:

<?xpacket begin="รฏยปยฟ" id="W5M0MpCehiHzreSzNTczkc9d"?> <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 4.2.2-c063 53.352624, 2008/07/30-18:12:18 ">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <rdf:Description rdf:about="" xmlns:exif="http://ns.adobe.com/exif/1.0/"> <xmp:Label>Enhanced</xmp:Label>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>

I am trying to use this to set the Label as "Enhanced". However I keep getting an "Error opening the template" message. What am I missing?

By recording an action which saves the jpg as a copy, I can at least save the file with ‘ copy’ after it. Is there any way to change this to ‘Edited’? Can I also paramaterise the save location so that it will save in whatever location the file was opened in? Cheers.
PR
Paul_R
Oct 21, 2008
Using a script you should be able to do everything, for the labelling you can use BridgeTalk, I might get chance tomorrow to write something for you.
PR
Paul_R
Oct 21, 2008
This should do it…

#target photoshop

if (!BridgeTalk.isRunning("bridge")) BridgeTalk.launch("bridge");

if(documents.length >0){

var originalFile = activeDocument.fullName.fsName;

var saveFile = activeDocument.fullName.fsName.slice(0,-4)+"_edited.jpg";

SaveJPEG(saveFile, 10);

activeDocument.close(SaveOptions.DONOTSAVECHANGES);

labelPic(originalFile,"Original");

labelPic(saveFile,"Enhanced");

}

function labelPic(file,tag) {

var bt = new BridgeTalk;

bt.target = "bridge";

var myScript = "try {";

myScript += "var file = new Thumbnail(\’"+file+"\’);";

myScript += "var md = file.synchronousMetadata;";

myScript += "md.namespace = \"http://ns.adobe.com/xap/1.0/\";";

myScript +="md.Label = \’"+ tag +"\’;";

myScript += "}catch(e){};";

bt.body = myScript;

bt.send();

}

function SaveJPEG(saveFile, jpegQuality){

jpgSaveOptions = new JPEGSaveOptions();

jpgSaveOptions.embedColorProfile = true;

jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;

jpgSaveOptions.matte = MatteType.NONE;

jpgSaveOptions.quality = jpegQuality; //1-12

activeDocument.saveAs(new File(saveFile), jpgSaveOptions, true,Extension.LOWERCASE);

}
AH
Aaron_Hayward
Oct 22, 2008
Thanx for the code Paul, iv been trying to solve this problem also.
PR
Paul_R
Oct 22, 2008
You are very welcome Aaron.
PS
P_Shopper
Oct 22, 2008
Thank you very much for that Paul, it’s very much appreciated! Could I please ask how to run it though? ๐Ÿ™‚ I’ve been googling what to do with BridgeTalk scripts and I haven’t found out yet what I need to do to run this or how to call it from photoshop. I’m not a programmer and I can’t seem to find anything in the manual about Bridgetalk. Thank you. JW
PR
Paul_R
Oct 23, 2008
This is a Photoshop script.
Copy the script and paste it into "ExtendScript Toolkit" this comes with PhotoShop. Save the script to:
It should create a script FileName.jsx (CS2/CS3) or FileName.js (cs) PC:- C:/Program Files/Adobe/Adobe Photoshop CS#/Presets/Scripts/ Mac:- [hard drive]/Applications/Adobe Photoshop CS#/Presets/Scripts/

To run the script :
File – Scripts – (select script)
You can also create an action to do the above and assign a function key. Another way would be to asign a shortcut key via
Edit – Keyboard Shortcuts – File, go down to scripts and the assign a shortcut.

Hope this helps.
PS
P_Shopper
Oct 23, 2008
Paul, that’s so cool! :-> Thank you very much indeed for that!!

Could I ask though – is it CS3 or 32 bit specific? I’ve just installed CS4 (64bit) and I’ve tried running it on a variety of files. A file copy is created with "_edited" after it, but the "Enhanced" tag is not added to the new one, not is the ‘Original’ tag added to the original file. If there is a previous label it is still present on the copy and if there was none before, there is none on the copy. I have tried running the script manually and as an action, but I am not getting the ‘Enchanced’ or ‘Original’ labels I clearly see in the code.

Could you possibly comment if I’m doing something wrong, or if the code may need to be tweaked for CS4? Thanks sooooo much. ๐Ÿ™‚
PS
P_Shopper
Oct 23, 2008
Paul, that’s so cool! :-> Thank you very much indeed for that!!

Could I ask though – is it CS3 or 32 bit specific? I’ve just installed CS4 (64bit) and I’ve tried running it on a variety of files. A file copy is created with "_edited" after it, but the "Enhanced" tag is not added to the new one, not is the ‘Original’ tag added to the original file. If there is a previous label it is still present on the copy and if there was none before, there is none on the copy. I have tried running the script manually and as an action, but I am not getting the ‘Enchanced’ or ‘Original’ labels I clearly see in the code.

Could you possibly comment if I’m doing something wrong, or if the code may need to be tweaked for CS4? Thanks sooooo much. ๐Ÿ™‚
PR
Paul_R
Oct 23, 2008
Very strange, I have tested it on Photoshop CS3 and CS4 on a PC with 32bit Vista Home Premium and the labels update without a problem.

I am a bit stuck as I don’t have a 64bit system to see where the problem lies.

I wonder if anyone out there could do some tests?
PS
P_Shopper
Oct 23, 2008
I just re-installed CS3 32bit, shut down Bridge CS4 and Photoshop CS4, opened up CS3 Photoshop. and Bridge and ran the script. I got the same result. :-/ I.e. I get a copy with "_edited", but not label adjustment takes place. I’m running Vista 64 bit (funnily enough ;-). Sooooo close. :-/ Can anyone else give this a spin on a 64 bit system? Cheers.
PS
P_Shopper
Oct 23, 2008
OK, I tried running Bridge and PS CS4 as administrator – no dice. I tried saving the script using the CS3 script manager – no dice. I tried firing up my laptop and running it on Windows XP (32-bit) with CS3 – no dice. :-/

Is there a debug mode to the scrip edit I can run to see what is wrong? If so, what am I looking for in terms of warning messages etc.?
PR
Paul_R
Oct 23, 2008
I have modified the function slightly, could you try this version please?

#target photoshop

if (!BridgeTalk.isRunning("bridge")) BridgeTalk.launch("bridge");

if(documents.length >0){

var originalFile = activeDocument.fullName.fsName;

var saveFile = activeDocument.fullName.fsName.slice(0,-4)+"_edited.jpg";

SaveJPEG(saveFile, 10);

activeDocument.close(SaveOptions.DONOTSAVECHANGES);

labelPic(originalFile,"Original");

labelPic(saveFile,"Enhanced");

}

function labelPic(file,tag) {

var bt = new BridgeTalk;

bt.target = "bridge";

var myScript = "";

myScript += "var file = new Thumbnail(\’"+file+"\’);";

myScript += "var md = file.synchronousMetadata;";

myScript += "md.namespace = \"http://ns.adobe.com/xap/1.0/\";";

myScript +="md.Label = \’"+ tag +"\’;";

bt.body = myScript;

bt.send();

}

function SaveJPEG(saveFile, jpegQuality){

jpgSaveOptions = new JPEGSaveOptions();

jpgSaveOptions.embedColorProfile = true;

jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;

jpgSaveOptions.matte = MatteType.NONE;

jpgSaveOptions.quality = jpegQuality; //1-12

activeDocument.saveAs(new File(saveFile), jpgSaveOptions, true,Extension.LOWERCASE);

}
PS
P_Shopper
Oct 24, 2008
Ah – now we are getting somewhere. First the bad news – it did not initially work. I.e. I got the same results as before, a new file was created with "_edited" appended, but neither of the files were tagged.

On a hunch I created a new file in CS4, saved it a jpg and ran your script. It worked! Both the files were tagged as expected, i.e. with ‘Original’ and ‘Enchanced’. I then experimented further with a variety of jpgs. I found that files that had Adobe rating metadata written to them could be a bit hit or miss. I.e. the script seems to work on all jpgs without metadata (so far), and also was OK with files that had been labeled, but files that have been rated (using Bridge) often don’t get tagged with the lables. Currently I am working way through a set of photos of families which have all been rated, which is why I think I am seeing the issue so much. Could there be a conflict with rating metadata already in the jpg? It did sometimes work however, which is very odd. I have tried to test jpgs from the same camera which were all acquired in the same manner (using Downloader Pro). I am still getting inconsitent results.

Do you think could be a metadata conflict somewhere that could be causing this? Thank you very much.
PR
Paul_R
Oct 25, 2008
Very interesting, I will rate a few pictures and do some tests, might not be today though as have to go out. I have been trying to edit the metadata within Photoshop (file & layers) and this seems to work but haven’t found a way of editing metadata in external files from Photoshop except using BridgeTalk to Bridge.
PR
Paul_R
Oct 26, 2008
I’ve tried with about 40 different rated pictures and could not get it to fail, so don’t know where to go from here.
Sorry.

MacBook Pro 16” Mockups ๐Ÿ”ฅ

– in 4 materials (clay versions included)

– 12 scenes

– 48 MacBook Pro 16″ mockups

– 6000 x 4500 px

Related Discussion Topics

Nice and short text about related topics in discussion sections