6 Replies Latest reply: Sep 29, 2011 2:40 AM by Juano Hunt RSS

    Rename the current active file?

    Juano Hunt Community Member

      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?

        • 1. Re: Rename the current active file?
          Muppet Mark Community Member

          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…

          • 2. Re: Rename the current active file?
            Juano Hunt Community Member

            Ah, OK. Thanks for letting me know.

            • 3. Re: Rename the current active file?
              Pedro Cortez Marques Community Member

              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.

              • 4. Re: Rename the current active file?
                Chris Cox Adobe Employee

                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.

                • 5. Re: Rename the current active file?
                  JJMack Community Member

                  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.

                  • 6. Re: Rename the current active file?
                    Juano Hunt Community Member

                    Thanks Chris and JJMack for the explanation.

                     

                    And thanks Pedro, I might try something like that.