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.
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.
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.
Here is what I'm trying to do just to clarify a bit better.
1 Open Document
2 Duplicate document via script to remove COPY at end of filename.
3 Close original document
4. Run action to make the duplicated copy B&W and change the background layer name to BW
5. Run script to change the name of document to "Document Name + activeLayerName
I get that far but I can't figure out how to return back to Photoshop with the documents replacement name. The only thing I can do is to make a new document with the new name but that's not what I need. Since the duplicated file hasn't been saved as yet I thought replacing the document name would be simple.
Thanks for any help!
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.
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.
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] );"
North America
Europe, Middle East and Africa
Asia Pacific