Copy link to clipboard
Copied
I am very new to scripting. I am looking to create a script that will save a .tif file with LZW compression to a file in a directory based on the current image filename. If that directory doesn't exist it will create it. All of my filenames are based on a 7 digit system.
For example... I want to take file name "123-456_A" and put it in the following folder system...
Product(Starting folder on the server)
-1
--12
---123
----123-
-----123-4
------123-45
-------123-456(Final Folder)
The "_A" etc will be ignored. Is this possible?
a folder hierarchy like yours doesn't make any sense for me, sorry. But anyway, try this:
...// folder_saveTif_inFolderBasedOnFilename.jsx
// https://forums.adobe.com/thread/2268221
// regards pixxxel schubser
// only file names eg 123-456_A or 100-123_Z allowed
var aDoc = activeDocument, nme = aDoc.name.replace(/\.[^\.]+$/,""), reg = /^\d{3}-\d{3}_./, tmp = nme.split("");
checkAndSave();
function checkAndSave() {
if( reg.test( nme ) == false) {
alert ("wrong file name"); return;
Copy link to clipboard
Copied
Please post screenshots illustrating the task and Folder structure better.
And please explain what exactly you mean by
save a .tif file with LZW compression
Save a copy of the active File? Save the active File as a new file?
With Layers or flattened?
Copy link to clipboard
Copied
Would be saving the active file as a new file with the following TIF options.
Copy link to clipboard
Copied
a folder hierarchy like yours doesn't make any sense for me, sorry. But anyway, try this:
// folder_saveTif_inFolderBasedOnFilename.jsx
// https://forums.adobe.com/thread/2268221
// regards pixxxel schubser
// only file names eg 123-456_A or 100-123_Z allowed
var aDoc = activeDocument, nme = aDoc.name.replace(/\.[^\.]+$/,""), reg = /^\d{3}-\d{3}_./, tmp = nme.split("");
checkAndSave();
function checkAndSave() {
if( reg.test( nme ) == false) {
alert ("wrong file name"); return; }
else { tmp.splice(3,1); tmp.splice(-2); tmp[2] += "-";
for( i = 1; i < 6; i++ ) { tmp = tmp[i-1] + tmp; };
var saveFol = Folder ("~/Desktop");
for ( i = 0; i < tmp.length; i++ ) {
saveFol = Folder( saveFol + "/" + tmp );
if (!saveFol.exists) { saveFol.create() };
};
var saveName = "/" + nme + ".tif";
var saveFile = new File( saveFol + saveName );
if( saveFile.exists ) { alert( saveFile + "\nFile already exists - not saved now" ); return; };
saveAsTIFF( saveFile ); alert( saveFol + saveName + " saved" )
//aDoc.close( SaveOptions.DONOTSAVECHANGES );
}; return;
};
function saveAsTIFF( saveFile ) {
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.layers = true;
tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
activeDocument.saveAs( saveFile, tiffSaveOptions, false );
}
This snippet should create the wished folder hierarchy (on your desktop) based on the given example file name.
Have fun
Copy link to clipboard
Copied
I didn't design the folder system.... I just have to use it Is there anyway I can set an absolute path(?) that points to a location on a sever verses the desktop? I am on a Mac and tried putting in the path but it just returns and error.
Copy link to clipboard
Copied
I should add that it is an smb:// path
Copy link to clipboard
Copied
what is the problem?
At first: I'm not really familiar with Mac OS and server paths.
Do you have a screenshot of the part of your desktop which shows your server icon?
Eg the name of the icon is "Transfer". Maybe this name is different to the real name of the server (eg sxyztech)
One possible way to find the path is: open a file which is located directly on Transfer/yourExampleFile.psd
Run this line of code:
alert(activeDocument.path)
On your Mac you should get now a result like this:
/Transfer/yourExampleFile.psd
And now you can try to replace this line of my code:
var saveFol = Folder ("~/Desktop");
with this:
var saveFol = Folder ("/Transfer");
Perhaps this helps you to find your way.
Have fun
And give a feedback please. I'm very interested for your answer.
Copy link to clipboard
Copied
That worked great to find the correct path. Thank you! One thing that I have noticed is that it is creating the "100-" folder in the wrong place. This is so close and I am very grateful!
It should show up as the highlighted folder above but instead it is showing as "100-" where it should be "100".
To add complication, my predecessor deviated from the folder system in spots. In the example below the "203-" folder was skipped and went directly into the "203-X" numbering.
Because all of these files are linked to another program I can't change the existing structure. I can make sure it is correct going forward but not anything that is already there. Is there anyway to include an "If" or "else" to take this into account? I realize this is asking a lot and I may have to manual correct these items.
Thank you so much for your help so far! This has been the absolute closest I have come to making his script a reality after lots of trial and error.
Copy link to clipboard
Copied
The first one is easy.
Replace line #12 and #13 in my code with:
else { tmp.splice(-2); //tmp.splice(3,1); tmp.splice(-2); tmp[2] += "-";
for( i = 1; i < 7; i++ ) { tmp = tmp[i-1] + tmp; };
Have fun
The second part is more complex. Sorry but I don't want spend time for check this now.
Furthermore it is another question.
Copy link to clipboard
Copied
Thank you for all of your help! It is very appreciated!!!
Copy link to clipboard
Copied
This script has been working perfect for me! Is there a way to alter it for files that have a naming structure of ZZ12345_A ? Basically I want it to read any 7 digit filename and put it in the coordinating folder.
Copy link to clipboard
Copied
Hi kareyh56356757,
hmmh?
ZZ12345_A is not a 7 digit filename.
Furthermore:
which letters and/or digits in the filename are fix and which ones are variable?
Copy link to clipboard
Copied
I realized my mistake and fixed it with the following...
var aDoc = activeDocument, nme = aDoc.name.replace(/\.[^\.]+$/,""), reg = /^\w{2}\d{5}_./, tmp = nme.split("");
checkAndSave();
I had been trying to read the letters as digits.
Copy link to clipboard
Copied
Regex is not easier way off. You should understand the syntax before.
Try this snippet (standalone):
var a = "1234567_A";
var b = "ZZ12345_A";
var nme = a.replace(/\.[^\.]+$/,""), reg = /^\w{2}\d{5}_./, tmp = nme.split("");
checkAndSave();
nme = b.replace(/\.[^\.]+$/,""), reg = /^\w{2}\d{5}_./, tmp = nme.split("");
checkAndSave();
nme = a.replace(/\.[^\.]+$/,""), reg = /^[A-Z]{2}\d{5}_./, tmp = nme.split("");
checkAndSave();
nme = b.replace(/\.[^\.]+$/,""), reg = /^[A-Z]{2}\d{5}_./, tmp = nme.split("");
checkAndSave();
function checkAndSave() {
if( reg.test( nme ) == false) {
alert (reg+" better regex do not find: "+ nme); return; }
else { alert (reg+" found: "+nme) }
}
The reason is: \w will find all "word signs" eg digits AND letters
Have fun