10 Replies Latest reply on May 29, 2012 1:17 AM by -hans-

    File name extension removal

    StevePenn

      Hi. Have just upgraded to CS6 and have an issue with a script we use in production. The script exports a .ps file to a location but we are having to remove the .indd extension each time we use it (eg filename.indd.ps becomes filename.ps). The previous version of indesign we were able to save the file without it's .indd extension and when it was opened the extension stayed hidden. CS6 can save without the extension but when the file is open the extension is visible again. Any ideas? cheers

        • 1. Re: File name extension removal
          csm_phil Level 4

          Hi Steve,

           

          Can you please try the below JS code.

           

          I am not tested the below code in CS6 just tested only CS5.5

           

          var myDoc = app.activeDocument;
          var myPath = myDoc.filePath;
          var myNEWName = (myDoc.name.replace(".indd",".ps"));
          var myDc = new File(myPath+"/"+myNEWName);
          myDoc.save(myDc);
          myDoc.saveACopy(myDc);
          

           

           

          thx

          csm_phil

          • 2. Re: File name extension removal
            StevePenn Level 1

            Hey...cheers for that, very quick response. I stupidly forgot to mention that the script that we have is an AppleScript.

            • 3. Re: File name extension removal
              -hans- Level 4

              hi,

               

              well some code could have been nice ...

               

              For general, you can use this handler which starts "system events"

               

              Input alias & new suffix -> returns new filename

               

              Code:

               

              set thisWillBeTheNewFileName to my setFileName(choose file, "ps") --example usage

               

              on setFileName(myAlias, myNewSuffix)

                  tell application "System Events"

                      set {myName, myExtension} to {name, name extension} of disk item (myAlias as text)

                      if myExtension is not "" then

                          set {tid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, myExtension}

                          set myName to text 1 thru -2 of (text item 1 of myName)

                      end if

                      set newName to myName & "." & myNewSuffix

                  end tell

                 

                  return newName

                 

                  set AppleScript's text item delimiters to tid

                 

              end setFileName

              • 4. Re: File name extension removal
                sstanleyau Level 4

                Firing up System Events seems like overkill (and it's quite slow to launch), especially as you're using text item delimiters anyway. You could just use:

                 

                on changeExtension(oldPath, ext)

                          set saveTID to AppleScript's text item delimiters

                          set AppleScript's text item delimiters to {":"}

                          set justName to text item -1 of oldPath

                          if justName contains "." then

                                    set AppleScript's text item delimiters to {"."}

                                    set newPath to text 1 thru text item -2 of oldPath

                          else

                                    set newPath to oldPath

                          end if

                          set AppleScript's text item delimiters to saveTID

                          return newPath & "." & ext

                end changeExtension

                 

                Of course if you're happy to use some outside help, my ASObjC Runner is quicker and easier than System Events:

                 

                tell application "ASObjC Runner" to set newPath to file path from oldPath replacing extension ext


                2 people found this helpful
                • 5. Re: File name extension removal
                  StevePenn Level 1

                  Thanks all for your help everyone. Will pass it on to our IT guys.

                   

                  Shane, think our IT guys might have already been in contact. Was a script you wrote for us a while back (cs2) that we are using. Cheers again

                  • 6. Re: File name extension removal
                    sstanleyau Level 4

                    I suspect the problem is that InDesign has hijacked the text class. It's just a matter of miving the relevant bit of code outside the 'tell app "InDesign"' block.

                    • 7. Re: File name extension removal
                      StevePenn Level 1

                      Cheers mate. Will pass it on. Off work today so can't try it myself.

                      Thanks again

                      • 8. Re: File name extension removal
                        -hans- Level 4

                        Hi,

                         

                         

                        Shane Stanley wrote:

                         

                        Firing up System Events seems like overkill (and it's quite slow to launch), especially as you're using text item delimiters anyway. You could just use:

                         


                        of course you're right assuming a text path is send to the handler, System Events will handle text path or alias. As the poster couldn't show any source code it seemed safer ;-)

                         

                        Have a nice day

                        • 9. Re: File name extension removal
                          sstanleyau Level 4

                          -hans- wrote:

                           

                          of course you're right assuming a text path is send to the handler, System Events will handle text path or alias.

                          That's a good point, but a simple "as string" will solve it in the first example.

                           

                          The second example, using ASObjC Runner, will actually accept an alias, file, HFS path or even POSIX path.

                          • 10. Re: File name extension removal
                            -hans- Level 4

                            Of course! you're right ;-)

                             

                            I just took the system events handler from my pocket-library ...

                             

                            ASObjC Runner:

                             

                            Thx for programming