Copy link to clipboard
Copied
I am trying to create an process and action that does the following:
I am good on steps 1 through 5 and 7, but cannot figure out step 6 in a Win7 environment. Basically, I edit images in a staging folder before moving them to the parent. Then the parent folder is cleaned up and pulled into a permanent storage location. So the workspace looks like this:
Starting file structure (three .bmp files and two subfolders in ...\parent)
...\parent\File1.bmp {old}
...\parent\File2.bmp
...\parent\File3.bmp
...\parent\Delete\
...\parent\Working\
Next step: New File1.tif is sourced and placed in Working Folder, Current File1 is moved to Delete Folder
...\parent\File2.bmp
...\parent\File3.bmp
...\parent\Delete\File1.bmp {old}
...\parent\Working\File1.tif
Next step: Edit File1.tif in Working Folder and run final action - Save As .bmp in one folder up (...\parent\)
...\parent\File1.bmp {new}
...\parent\File2.bmp
...\parent\File3.bmp
...\parent\Delete\File1.bmp {old}
...\parent\Working\File1.tif
Last step, Cleanup: Remove the Delete/Working subfolders, move files to new location
...\parent\File1.bmp {new}
...\parent\File2.bmp
...\parent\File3.bmp
How can I do the Save As step??
Copy link to clipboard
Copied
At first: Please do not use the name parent for a folder that you want to call with scripting. parent has a function in javascript.
// http://forums.adobe.com/thread/1251089?tstart=0
// required on desktop: "File1.bmp" and 2 folders named "Delete" and "Working"
// regards pixxxelschubser
var aFileName = "File1.bmp";
// var yourFilePath = "…/PleaseName_It_Not_Parent/"; //instead of the next line
var aFilePath = "~/Desktop/";
var DelFolder = aFilePath+"Delete/";
var WorkFolder = aFilePath+"Working/";
var aFile = File(aFilePath+aFileName);
var aDoc = open (aFile);
var DelFile = new File(DelFolder+aDoc.name);
var saveName = aDoc.name.replace (/\.bmp$/,'.tif');
var saveFile = new File(WorkFolder+saveName);
// do something
if(aFile.copy(DelFile)){
aFile.remove();
} else {alert("File can't be move to DeleteFolder")}
SaveAsTIFF(saveFile);
activeDocument.close( SaveOptions.DONOTSAVECHANGES );
function SaveAsTIFF(saveFile){
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.layers = true;
activeDocument.saveAs(saveFile, tiffSaveOptions, false);
}
Repeat the saving process (but now tif to bmp) and delete the tif file.
Have fun
Copy link to clipboard
Copied
I am just using parent to illustrate. It actually looks like this, where parent and file names are variable and each edit work driver may require editing a different {old} bmp:
...\04969\1234_1.bmp {old}
...\04969\1234_2.bmp
...\04969\1234_3.bmp
...\04969\Delete\
...\04969\Working\
How would the coding change for the following:
1) Working multiple edits and editing different files each time
2) Working multiple edits and and the names of the parent directory changed for each edit?
3) Working multiple edits and and the names of the files changed for each edit?
So Edit 1:
...\04969\1234_1.bmp
...\04969\1234_2.bmp {old}
...\04969\1234_3.bmp
...\04969\Delete\
...\04969\Working\
Edit 2:
...\04969\1236_1.bmp
...\04969\1236_2.bmp
...\04969\1236_3.bmp {old}
...\04969\Delete\
...\04969\Working\
Edit 3:
...\89001\2255_1.bmp {old}
...\89001\2255_2.bmp
...\89001\2255_3.bmp
...\89001\Delete\
...\89001\Working\
Copy link to clipboard
Copied
How would the coding change for the following:
It is really hard to say how to change your code without seeing the code so we know how you are doing it now.
But here are some more examples for working with files.
var myFile = new File('~/desktop/04969/1234_1.bmp');
// different name
var myNewFile = new File( myFile.parent+'/1234_2.bmp');
alert(myNewFile);
// different folder
myNewFile = new File( myFile.parent.parent+'/'+myFile.name);
alert(myNewFile);
// or different folder this way
var myNewFolder = new Folder('~/desktop/temp');
myNewFile = new File( myNewFolder+'/'+myFile.name);
alert(myNewFile);
// new folder and new name
myNewFolder = new Folder('~/desktop/temp');
myNewFile = new File( myNewFolder+'/1234_3.bmp');
alert(myNewFile);
Copy link to clipboard
Copied
var CurrentFolder = activeDocument.path;
var parentFolder = decodeURI(activeDocument.path.parent);
$.writeln(parentFolder);
BMPFile = new File(parentFolder, activeDocument.name)
BMPsaveOptions = new BMPSaveOptions();
BMPsaveOptions.depth = BMPDepthType.TWENTYFOUR;
BMPsaveOptions.osType = OperatingSystem.WINDOWS;
activeDocument.saveAs(BMPFile, BMPsaveOptions, true,Extension.LOWERCASE);
Here is my current code. I am getting a general PS error on the last line of code saying this functionality may not be available in my version of PS6.
Copy link to clipboard
Copied
You are creating the file object incorrectly.
var BMPFile = new File(parentFolder+'/'+activeDocument.name);
Copy link to clipboard
Copied
Note: if the document was opened from a file( not a newly created document ) then activeDocument.name will already have an extension. Unless you remove the existing extension you may end up with a saved file named something like 'myDoc.tif.bmp'
Copy link to clipboard
Copied
Works!
Interesting though....I am opening in .jpg and it does not carry over the .jpg extension when it saves. Do i need to add extra code to drop the current extension?
Last question...I have saved as a .jsx file to the scripts folder. The script shows up in the File>scripts menu. When I run the script it runs and then opens a java editor. How do I keep from opening the editor?
Copy link to clipboard
Copied
To avoid the ExtendScript Toolkit editor opening remove the line $.writeln(parentFolder);
$.writeln() writes to the javascript console in the editor and you scirpt opens the editor to complete that line.
If the extension is being removed by the saveAs method, I wouldn't worry about it.
Copy link to clipboard
Copied
Perfect! Many thanks!
//Save current file one directory up
var CurrentFolder = activeDocument.path;
var parentFolder = decodeURI(activeDocument.path.parent);
//$.writeln(parentFolder);
var BMPFile = new File(parentFolder+'/'+activeDocument.name);
BMPsaveOptions = new BMPSaveOptions();
BMPsaveOptions.depth = BMPDepthType.TWENTYFOUR;
BMPsaveOptions.osType = OperatingSystem.WINDOWS;
activeDocument.saveAs(BMPFile, BMPsaveOptions, true,Extension.LOWERCASE);
Copy link to clipboard
Copied
Parent is a file and folder object property. You can use that property to determine a file's current folder and so on up the folder chain.
var myFile = new File('~/desktop/someFolder/someSubFolder/test.bmp');
alert('Same Folder = '+myFile.parent);
alert('One folder up = '+myFile.parent.parent);
Find more inspiration, events, and resources on the new Adobe Community
Explore Now