Skip navigation
StevePenn
Currently Being Moderated

File name extension removal

May 28, 2012 2:25 AM

Tags: #file #indesign #cs6 #name #scripts #file_extensions

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

 
Replies
  • Currently Being Moderated
    May 28, 2012 4:51 AM   in reply to StevePenn

    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

     
    |
    Mark as:
  • Currently Being Moderated
    May 28, 2012 11:28 AM   in reply to StevePenn

    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

     
    |
    Mark as:
  • Currently Being Moderated
    May 28, 2012 7:10 PM   in reply to -hans-

    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


     
    |
    Mark as:
  • Currently Being Moderated
    May 28, 2012 7:27 PM   in reply to StevePenn

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    May 28, 2012 11:16 PM   in reply to Shane Stanley

    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

     
    |
    Mark as:
  • Currently Being Moderated
    May 28, 2012 11:35 PM   in reply to -hans-

    -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.

     
    |
    Mark as:
  • Currently Being Moderated
    May 29, 2012 1:17 AM   in reply to Shane Stanley

    Of course! you're right ;-)

     

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

     

    ASObjC Runner:

     

    Thx for programming

     
    |
    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