Run action determined by file name suffix

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Limey

Run action determined by file name suffix

Post by Limey »

Hi folks,
I recently requested help to read a portion of a file name and use it to find the correct path from an archive of paths. Mike hale was able to give me exactly what I needed and as a result of that I have been able to automate a whole workflow with a mindless drag and drop procedure. Well, it's not totally mindless yet... There is one more thing I can do to put it over the top and truly make the process idiot proof.

I currently have a single action that has everything in it to give me my 3 sizes of print. I have 3 droplets on the desktop that reflect the action configured to 3 different sizes.
Our programmers will be providing us with files that use a naming convention that I determined to give us everything we need. The script mike provided ( http://ps-scripts.com/bb/viewtopic.php? ... ile#p26863 ) used the Pattern#.

The naming convention is as follows.

PO# (4926308)
Pattern# (QT0005)
Shirt Sku# (4M289)
Size of print (sml, med, lrg)

Example: 4926308-QT0005-4M289-med


REQUEST:
I need a script that run 1 of 3 actions depending on the "size of print" as listed in the file name. We can always use 3 letters for the size to make the script easier (sml and med instead of sm and med). The size of print will always be at the end of the file name after the 3rd hyphen.

So again we need to read the file name but this time look for what is after the 3rd hyphen or the last 3 characters of the file name of the active document then run a action.
For this to work I realize I will need to create 3 separate actions instead of using the single action that I am currently using with the multiple droplets.

Then I think a switch similar to what I have used before would do the job.
Code: Select allcase "sml": doAction("print size small","Q-Tee production actions"); break;
   case "med": doAction("print size medium","Q-Tee production actions"); break;
   case "lge": doAction("print size large","Q-Tee production actions"); break; 

I have this from Mike's action Code: Select allvar searchName = doc.name.match(/[^-]+-([^-]+)-.+/)[1]; which would need to change to copy after the 3rd hyphen.

The trouble is putting the pieces together.

If anyone can help (Mike?) This would really help simplify the process because we can then drop folders on a single droplet instead of multiple files onto multiple droplets.


Cheers,
Limey (Paul)

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

pfaffenbichler

Run action determined by file name suffix

Post by pfaffenbichler »

I’m not good with RegExp but maybe this helps; theString would have to be the name naturally …
Code: Select allvar theString = "asaf_afkjhe_saf_afk_med.tif";
var thePart = theString.match(/_\D{3,3}\.\D{2,4}$/i);
if (thePart != null) {alert (thePart[0].slice(1,4))};
Mike Hale

Run action determined by file name suffix

Post by Mike Hale »

Sorry I couldn't respond to this sooner. I think it would be eaiser and more flexible to give up on RegExp and use the string split method.
Code: Select allvar someString = '4926308-QT0005-4M289-med';
var someArray = someString.split('-');
alert(someArray[3]);
Limey

Run action determined by file name suffix

Post by Limey »

Hi folks,
I have to give in I am afraid and ask for guidance. I have been trying to get this to work using dual splits to first remove the extension and then to isolate the size (sml,med,lrg) at the end of the file name.

If I just use the ('-') then it works fine but it gives me "lrg.jpg" for example.
If I do as shown below I get 4763714-QT0001-S3452-lrg with the split('.')
So in theory I should be able to now run the split as you have shown and I would get just "lrg"

This isn't working. Instead I get fileName.split is not a function

I have done all I can do and spent hours trying to figure out why this is happening.
Please could you help?


Code: Select all#target photoshop
var doc = app.activeDocument.name;
alert(doc);
var fileName = doc.split('.');
alert(fileName[0]);
var printSize = fileName.split('-');
alert(printSize[3]);

switch(printSize){
   //case 1 :  app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); break;
   case "lrg":  doAction("Qtee-Print lrg","Qtee print actions"); break;
   case "med": doAction("Qtee-Print med","Qtee print actions"); break;
   case "sml": doAction("Qtee-Print sml","Qtee print actions"); break;
   default : break;
}

Thanks,
Paul
Limey

Run action determined by file name suffix

Post by Limey »

Feeling pretty good... I know it's simple but I was able to piece something together that worked!

Code: Select all#target photoshop
var doc = app.activeDocument.name;
//alert(doc);
var part = doc.slice(0,-4);
var printSize = part.split('-')


switch(printSize[3]){
   //case 1 :  app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); break;
   case "lrg":  doAction("Qtee-Print lrg","Qtee print actions"); break;
   case "med": doAction("Qtee-Print med","Qtee print actions"); break;
   case "sml": doAction("Qtee-Print sml","Qtee print actions"); break;
   default : break;
}


The double split didn't work but the slice and split was fine!

Thanks to pfaffenbichler and Mike for your input. I feel like I took another little step on a long path to enlightenment

Paul (Limey)