Skip navigation
Currently Being Moderated

Replace document name

Aug 5, 2012 6:38 AM

How could I replace a open document name with a new name?

 

I have a script that creates the new name but I can't figure out how to send the new name back to photoshop replacing the open document name.

 

Here is the current script:

*********************

layerN = activeDocument.activeLayer.name

var doc = app.activeDocument

var fname = doc.name.split(".")

var fname = fname[0]

 

 

var newDoc = doc.duplicate(fname+layerN,true)

//var newDoc = (fname+layerN,true)

 

 

app.activeDocument.name = newDoc

newDoc.flatten();

***************************

Right now this one makes a duplicate of the original document with the document name like I want, but I would rather just rename the original document instead of making a duplicate.

 

Any help is appreciated.

 
Replies
  • Currently Being Moderated
    Aug 5, 2012 11:24 PM   in reply to ocphotog

    Right now this one makes a duplicate of the original document with the document name like I want, but I would rather just rename the original document instead of making a duplicate.

    Why?

     

    In JavaScript »File« has a method »rename«.

    But if the file is currently open I doubt using that is a great idea.

     
    |
    Mark as:
  • JJMack
    3,409 posts
    Jan 9, 2006
    Currently Being Moderated
    Aug 6, 2012 5:19 AM   in reply to c.pfaffenbichler

    Most likely if the document has an assoiated file you can save the current document using "save();"  to insure any updates get written out  then you can rename the associated file with the name you want. Close the current document and open the renamed document.  

     

    Some of Photoshop Document Properties objects are read only for example:

    fullName File Read-only. The full path name of the document.

    name string   Read-only. The document's name.

    path File        Read-only. The path to the document.

     
    |
    Mark as:
  • JJMack
    3,409 posts
    Jan 9, 2006
    Currently Being Moderated
    Aug 7, 2012 6:17 AM   in reply to ocphotog

    Because the document is a new document a that was created as a dup of some othere document there is no File assocated with this new document.  When you created the document  you could have named it anything you wanted.  Also because the is no file associated with this document I beleive that if you save the document with the name you want that Photoshop will basicly rename the document to match the file it is now associated with. I think this is something that Photoshop does when a document with no file assocation gets assocated with a file. For example if I open one of my Camera RAW file through ACR into Photoshop the name in the image window title will be RAW_FILENAME.CR2  while it looks like there is a file assocation the document does not have a file assocation for Photoshop can not write CR2 raw file.  The document just needed a name so Photoshop gave it the raw file fame. Now if I save that Document as xxx.tif Photoshop will save the xxx.tif file and change the document  name from RAW_FILENAME.CR2 to xxx.tif and you will see the in the image window title.  While the Document name object is read only to scripts its not read only to Photoshop when there is no file assocation. Once there is a file assocation the document name is set and is read only to Photoshop now too.  Even if the document had a lot of changes and I go to the history Palette and see the RAW_FILENAME.CR2 snap shot followed by the open and history. If I step back to the open the name remains xxx.tif.

     

    So if there is no assocated file all you need do is to save the document to the filename you want the document to have and Photoshop will rename the document for you if the document truly had never been saved and has no file assocated with it.

     
    |
    Mark as:
  • JJMack
    3,409 posts
    Jan 9, 2006
    Currently Being Moderated
    Aug 7, 2012 1:14 PM   in reply to ocphotog

    Your using Javascript just look in the Photoshop Javascript guide method saveas

    saveAs (saveIn [, options] [, asCopy] [, extensionType])

     

    savein is the file your saving the document to the document should then be associated with that file and Photoshop should rename the document to match if the document had no file associated before.

     
    |
    Mark as:
  • JJMack
    3,409 posts
    Jan 9, 2006
    Currently Being Moderated
    Aug 7, 2012 7:58 PM   in reply to ocphotog

    As I wrote "When you created the document  you could have named it anything you wanted" Photoshop will generate a default name of "Original Doc Name Copy"  however you can override that name during the dupe operation if not with DOM code you can use scriptlistener code for the action manager. DOM code would be "duplicate ([name ] [, mergeLayersOnly] );"

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points