Skip to main content
Participating Frequently
September 28, 2011
Question

Rename the current active file?

  • September 28, 2011
  • 3 replies
  • 22964 views

I'm wanting a script to be able to rename open Photoshop files, if possible.

I cobbled this together from an existing script:

tell application "Adobe Photoshop CS5"

  activate

          set old_name to name of current document

          set dialog_result to display dialog ¬

                    "Rename active document:" default answer (old_name) ¬

                    buttons {"Cancel", "Rename"} default button 2 ¬

  with icon note

          if button returned of dialog_result = "Rename" then

                    set new_name to text returned of dialog_result

                    set d to properties of current document

                    if path of d is equal to missing value then

                              set name of current document to new_name

                    else

                              tell me to set the_file to POSIX file (d's path as text) as alias

                              tell application "Finder"

                                        set name of the_file to new_name

                              end tell

                    end if

          end if

end tell

If I run it it shows the dialogue window, but when I enter the new name and hit Return it throws out lots of errors.

Is something like this possible?

This topic has been closed for replies.

3 replies

Chris Cox
Legend
September 29, 2011

There is no "active file" -- documents in Photoshop are not necessarily related to a file on disk.

And you can always save them to a different name/path.

"Save As" is the only good way to change the association of a document with a file.

JJMack
Community Expert
Community Expert
September 29, 2011

As Chris wrote Photoshop is not a File Editor. Photoshop edits Photoshop Documents the current Document may or may not have a file on the system created fron the active document.  If if does have a file assocatation I sure with scripting you can perform file operations on the file  like delete, rename, move etc.  However the will not change the active document name. Basicly document name is read only.... well sort of read only for if the current document does not have a file assocation and you save it into you file system The docoument becomes assocated with a file and Photoshop will change the active document name.  Aslo when you open a RAW file through ACR the inage image window or tab may show something like imagename.cr2 there is not actually a file associated with the document for Photoshop can not save a Camera RAW file so if you save it as PSD or TiFF the window or tab will now show the file assocation imagename.psd|tif  not .cr2. The document name does not always change with a save for if you save the PSD as a jpeg after the jpeg images is saved the document reverts back to its layered and color depth state  and is still imagename.psd.  There is no active document associated with that saved jpeg file. You can open it and have two document open that look the same one being layered a and perhaps 16bit and the other flat and 8bit.

JJMack
Participating Frequently
September 29, 2011

Thanks Chris and JJMack for the explanation.

And thanks Pedro, I might try something like that.

Pedro Cortez Marques
Legend
September 28, 2011

Have you tried to "duplicate" the active document with the new name and close the old one? Its kind of work-arround the problem, but it might work the same.

Inspiring
September 28, 2011

Because name is a read only property… Either re-name files using your system or as part of a save as but not just with an open document… It not going to work…

Participating Frequently
September 28, 2011

Ah, OK. Thanks for letting me know.