Create folders with input prompt.

Discussion of Automation, Image Workflow and Raw Image Workflow

Moderators: Tom, Kukurykus

Mcquiff

Create folders with input prompt.

Post by Mcquiff »

I need to write a script; applescript or java script, to be run by the actions in Photoshop CS5

This is how my Action works in photoshop at the moment
FLATTEN LAYERS
Image sharpen
Save As JPG (to the HR (High Res) folder)
Select previous History state
Image size (size to width 1020 pixels)
Image sharpen
Save as JPG (to the LR(Low Res) folder)

I currently have to create the folders by hand first.




What I will need it to is create folders with a prompt for folder name.

Eg. Create folder on the desktop this needs to have the name "quiffy_WK??_HR"
and then a second folder "quiffy_WK??_LR"

Where the ?? refer to user input. hopefully I only want to type this once as it would need to be the same for each folder.

In the nature of the way that photoshop works I would need to be able to point photoshop after this to save files to them.
Mike Hale

Create folders with input prompt.

Post by Mike Hale »

If I understand what you want this is one way.
Code: Select allvar userInput = prompt('Some meanigful string to tell the user what to enter','default input');
if(userInput != null){// make sure the user did not cancel. May want to add other checks such as length
   var highResFolder = new Folder('~/Desktop/quiffy_WK'+userInput+"_HR");
   if(!highResFolder.exesits) highResFolder.create();
   var lowResFolder = new Folder('~/Desktop/quiffy_WK'+userInput+"_LR");
   if(!lowResFolder.exesits) lowResFolder.create();
}
Mcquiff

Create folders with input prompt.

Post by Mcquiff »

Oh God I thought I knew what I was doing! How what why where. Thanks for your input it makes sense that that is what I am trying to do. But How do I use it?

I thought I write it as a text file, then append .jsx to the end. Then as an action >file>script>browse.

If this it right, i got this message
Error 8: Syntax error.
Line: 1
-> {\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf350

Sorry far to new to this.

Just going to search it to find out how to use it.

Many Thanks
larsen67

Create folders with input prompt.

Post by larsen67 »

'exesits' should be 'exists' in 2 places… Just a typo must have been a long day…
Mike Hale

Create folders with input prompt.

Post by Mike Hale »

Yeah, typos R us.

But I'm not sure that is the reason for the error. With that typo the script would create the folder even if it already existed. And it is not on line one.

My guess it that the file was not saved as plain text. '\rtf1\ansi\...' makes me think that it was saved in some other format like rich text. Use an editor like ExtendScript Toolkit( installed with Photoshop), notepad, etc.
Mcquiff

Create folders with input prompt.

Post by Mcquiff »

Ok I am figuring it out.

And it almost works. The only thing now is my save command (straight from the photoshop>file>save as command) save it to where ever I last saved it. I need to then save it by default to the relevant folder, so the first save would go into the HR folder and then the second save to the LR folder.

Also I need the previous script to only ask me the once, as when I dump a whole load of images through it always asks me which week.

Thanks again

Matt
Mike Hale

Create folders with input prompt.

Post by Mike Hale »

That will be harder to script. For the script to remember the userinput and only prompt when you want to make a change it would need to be written as an automation plug-in. Also for it to control where the images are saved it would need to do the save. As far as I know there is no easy way for a script to change Photoshop's last used folder for the built-in open and save dialogs.

I'm not sure how those changes would fit in your workflow. I think that you will need to either break the current action up into single step actions or just script the whole process.
Mcquiff

Create folders with input prompt.

Post by Mcquiff »

Although this is getting complicated I found a script to convert an action
http://ps-scripts.cvs.sourceforge.net/v ... ision=1.29
So this is what it looks like below. In Steps 3 and 7 it references the save command. Near the top there is the code you help supplied. I've managed to get it to write into the correct folder, however when photoshop starts again it ask for input.

How can I get it to ask once or repeat back to line 23?


#target photoshop
//
// MIKEY2.jsx
//

//
// Generated Tue Feb 22 2011 18:51:25 GMT-0000
//

cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };

//
//==================== MIKEY ==============
//
var userInput = prompt('Enter Week Number','default input');
if(userInput != null){// make sure the user did not cancel. May want to add other checks such as length
   var highResFolder = new Folder('~/Desktop/Mikey_WK'+userInput+"_HR");
   if(!highResFolder.exists) highResFolder.create();
   var lowResFolder = new Folder('~/Desktop/Mikey_WK'+userInput+"_LR");
   if(!lowResFolder.exists) lowResFolder.create();
}
function MIKEY() {
// Flatten Image
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
executeAction(sTID('flattenImage'), undefined, dialogMode);
};

// Smart Sharpen
function step2(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putUnitDouble(cTID('Amnt'), cTID('#Prc'), 164);
desc1.putUnitDouble(cTID('Rds '), cTID('#Pxl'), 0.9);
desc1.putInteger(cTID('Thsh'), 0);
desc1.putInteger(cTID('Angl'), 0);
desc1.putBoolean(sTID("moreAccurate"), false);
desc1.putEnumerated(cTID('blur'), sTID("blurType"), cTID('GsnB'));
desc1.putString(sTID("preset"), "Default");
var desc2 = new ActionDescriptor();
desc2.putUnitDouble(cTID('Amnt'), cTID('#Prc'), 0);
desc2.putUnitDouble(cTID('Wdth'), cTID('#Prc'), 50);
desc2.putInteger(cTID('Rds '), 1);
desc1.putObject(cTID('sdwM'), sTID("adaptCorrectTones"), desc2);
var desc3 = new ActionDescriptor();
desc3.putUnitDouble(cTID('Amnt'), cTID('#Prc'), 0);
desc3.putUnitDouble(cTID('Wdth'), cTID('#Prc'), 50);
desc3.putInteger(cTID('Rds '), 1);
desc1.putObject(cTID('hglM'), sTID("adaptCorrectTones"), desc3);
executeAction(sTID('smartSharpen'), desc1, dialogMode);
};

// Save
function step3(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putInteger(cTID('EQlt'), 12);
desc2.putEnumerated(cTID('MttC'), cTID('MttC'), cTID('None'));
desc1.putObject(cTID('As '), sTID("JPEGFormat"), desc2);
desc1.putPath(cTID('In '), new File('~/Desktop/Mikey_WK'+userInput+"_HR"));
desc1.putBoolean(cTID('LwCs'), true);
executeAction(cTID('save'), desc1, dialogMode);
};

// Select
function step4(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated(cTID('HstS'), cTID('Ordn'), cTID('Prvs'));
desc1.putReference(cTID('null'), ref1);
executeAction(cTID('slct'), desc1, dialogMode);
};

// Image Size
function step5(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putUnitDouble(cTID('Wdth'), cTID('#Pxl'), 1500);
desc1.putBoolean(cTID('CnsP'), true);
desc1.putEnumerated(cTID('Intr'), cTID('Intp'), cTID('Bcbc'));
executeAction(sTID('imageSize'), desc1, dialogMode);
};

// Smart Sharpen
function step6(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putUnitDouble(cTID('Amnt'), cTID('#Prc'), 180);
desc1.putUnitDouble(cTID('Rds '), cTID('#Pxl'), 0.9);
desc1.putInteger(cTID('Thsh'), 0);
desc1.putInteger(cTID('Angl'), 0);
desc1.putBoolean(sTID("moreAccurate"), false);
desc1.putEnumerated(cTID('blur'), sTID("blurType"), cTID('GsnB'));
desc1.putString(sTID("preset"), "Default");
var desc2 = new ActionDescriptor();
desc2.putUnitDouble(cTID('Amnt'), cTID('#Prc'), 0);
desc2.putUnitDouble(cTID('Wdth'), cTID('#Prc'), 50);
desc2.putInteger(cTID('Rds '), 1);
desc1.putObject(cTID('sdwM'), sTID("adaptCorrectTones"), desc2);
var desc3 = new ActionDescriptor();
desc3.putUnitDouble(cTID('Amnt'), cTID('#Prc'), 0);
desc3.putUnitDouble(cTID('Wdth'), cTID('#Prc'), 50);
desc3.putInteger(cTID('Rds '), 1);
desc1.putObject(cTID('hglM'), sTID("adaptCorrectTones"), desc3);
executeAction(sTID('smartSharpen'), desc1, dialogMode);
};

// Save
function step7(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putInteger(cTID('EQlt'), 12);
desc2.putEnumerated(cTID('MttC'), cTID('MttC'), cTID('None'));
desc1.putObject(cTID('As '), sTID("JPEGFormat"), desc2);
desc1.putPath(cTID('In '), new File('~/Desktop/Mikey_WK'+userInput+"_LR"));
desc1.putBoolean(cTID('LwCs'), true);
executeAction(cTID('save'), desc1, dialogMode);
};

// Close
function step8(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
executeAction(cTID('Cls '), undefined, dialogMode);
};

step1(); // Flatten Image
step2(); // Smart Sharpen
step3(); // Save
step4(); // Select
step5(); // Image Size
step6(); // Smart Sharpen
step7(); // Save
step8(); // Close
};



//=========================================
// MIKEY.main
//=========================================
//

MIKEY.main = function () {
MIKEY();
};

MIKEY.main();

// EOF

"MIKEY2.jsx"
// EOF
Mike Hale

Create folders with input prompt.

Post by Mike Hale »

Try this. The first time it runs it will prompt for userinput. Following runs will not prompt. If you want it to prompt hold the alt key when running. Note only works in CS5.

Code: Select all#target photoshop
//
// MIKEY2.jsx
//
MIKEY();

function MIKEY() {
   try {
      var desc = app.getCustomOptions("21878580-3f53-11e0-9207-0800200c9a66");
      var userInput = desc.getString(stringIDToTypeID('userInput'));
   }catch(e) {}
   if(undefined == userInput || ScriptUI.environment.keyboardState['altKey']){
      var userInput = prompt('Enter Week Number','default input');
      if(userInput != null){// make sure the user did not cancel. May want to add other checks such as length
         try{
            var desc = app.getCustomOptions("21878580-3f53-11e0-9207-0800200c9a66");
         }catch(e){
            var desc = new ActionDescriptor();
         }
         desc.putString (stringIDToTypeID('userInput') , userInput );
         app.putCustomOptions( "21878580-3f53-11e0-9207-0800200c9a66", desc, true );
      }
   }
   var highResFolder = new Folder('~/Desktop/Mikey_WK'+userInput+"_HR");
   if(!highResFolder.exists) highResFolder.create();
   var lowResFolder = new Folder('~/Desktop/Mikey_WK'+userInput+"_LR");
   if(!lowResFolder.exists) lowResFolder.create();
   var saveName = decodeURI(app.activeDocument.name);
   saveName.match(/(.*)(\.[^\.]+)/) ? saveName = saveName.match(/(.*)(\.[^\.]+)/):saveName = [saveName, saveName];
   saveName = saveName[1];
   app.activeDocument.flatten();
   smartSharpen(164, 0.9, 0, 50, 1, 0, 50, 1);
   saveJPEG(highResFolder+'/'+saveName+'.jpg', 12, true);
   stepBackHistory();
   app.activeDocument.resizeImage (new UnitValue(1020,'px'), undefined, undefined, ResampleMethod.BICUBICSHARPER);
   smartSharpen(180, 0.9, 0, 50, 1, 0, 50, 1);
   saveJPEG(lowResFolder+'/'+saveName+'.jpg', 12, true);
   app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
};
function smartSharpen(amount,radius,shadowFade,shadowWidth,shadowRadius,highlightFade,highlightWidth,highlightRadius) {
   var desc1 = new ActionDescriptor();
   desc1.putUnitDouble(charIDToTypeID('Amnt'), charIDToTypeID('#Prc'), amount);
   desc1.putUnitDouble(charIDToTypeID('Rds '), charIDToTypeID('#Pxl'), radius);
   desc1.putInteger(charIDToTypeID('Thsh'), 0);
   desc1.putInteger(charIDToTypeID('Angl'), 0);
   desc1.putBoolean(stringIDToTypeID("moreAccurate"), false);
   desc1.putEnumerated(charIDToTypeID('blur'), stringIDToTypeID("blurType"), charIDToTypeID('GsnB'));
   desc1.putString(stringIDToTypeID("preset"), "Default");
   var desc2 = new ActionDescriptor();
   desc2.putUnitDouble(charIDToTypeID('Amnt'), charIDToTypeID('#Prc'), shadowFade);
   desc2.putUnitDouble(charIDToTypeID('Wdth'), charIDToTypeID('#Prc'), shadowWidth);
   desc2.putInteger(charIDToTypeID('Rds '), shadowRadius);
   desc1.putObject(charIDToTypeID('sdwM'), stringIDToTypeID("adaptCorrectTones"), desc2);
   var desc3 = new ActionDescriptor();
   desc3.putUnitDouble(charIDToTypeID('Amnt'), charIDToTypeID('#Prc'), highlightFade);
   desc3.putUnitDouble(charIDToTypeID('Wdth'), charIDToTypeID('#Prc'), highlightWidth);
   desc3.putInteger(charIDToTypeID('Rds '), highlightRadius);
   desc1.putObject(charIDToTypeID('hglM'), stringIDToTypeID("adaptCorrectTones"), desc3);
   executeAction(stringIDToTypeID('smartSharpen'), desc1, DialogModes.NO);
};
function saveJPEG(inFileName, inQuality, inEmbedICC) {
    var jpegOptions = new JPEGSaveOptions();
    jpegOptions.quality = inQuality;
    jpegOptions.embedColorProfile = inEmbedICC;
    app.activeDocument.saveAs( File( inFileName ), jpegOptions );
};
function stepBackHistory() {
   var desc1 = new ActionDescriptor();
   var ref1 = new ActionReference();
   ref1.putEnumerated(charIDToTypeID('HstS'), charIDToTypeID('Ordn'), charIDToTypeID('Prvs'));
   desc1.putReference(charIDToTypeID('null'), ref1);
   executeAction(charIDToTypeID('slct'), desc1, DialogModes.NO);
};
// EOF
Mcquiff

Create folders with input prompt.

Post by Mcquiff »

Wow!
You managed to cut down a lot of the gibberish in it too.
I ran it and it ran as it should.
The only thing that I did find that when I deleted the folders and emptied the trash. And then ran the code again it would never ask for the week number. Only as you mentioned by holding the alt key. Is there any way round this?

Many Thanks much appreciated.

Matt