Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Save As in Parent Directory

Guest
Jul 09, 2013 Jul 09, 2013

I am trying to create an process and action that does the following:

  1. Process outside of PS that stages files for edit
  2. PS Action to set selection(s) (each selection is on its own channel) on the original tif
  3. PS Action to open Background template file (.bmp file)
  4. PS Action to paste selection(s) in place (from channels) into .bmp file
  5. PS Action to flatten document
  6. PS Action to Save As a .bmp using the current file name one directory up
  7. Process outside of PS that cleans up and moves files

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??

TOPICS
Actions and scripting
2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Jul 09, 2013 Jul 09, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 10, 2013 Jul 10, 2013

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\

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jul 10, 2013 Jul 10, 2013

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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 19, 2013 Jul 19, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jul 19, 2013 Jul 19, 2013

You are creating the file object incorrectly.

var BMPFile = new File(parentFolder+'/'+activeDocument.name);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jul 19, 2013 Jul 19, 2013

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'

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 19, 2013 Jul 19, 2013

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jul 19, 2013 Jul 19, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 19, 2013 Jul 19, 2013
LATEST

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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jul 09, 2013 Jul 09, 2013

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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines