Skip navigation
Currently Being Moderated

Help Need for .zip creation instead of Package folder

Mar 2, 2011 8:23 AM

Hello every one,

I have script for Package creation which was modified by “Mi_D”. Script is working pretty well. It’s creating Package folder in same path. I am looking for small modification in this script. Instead of Package folder I need a .zip file in the same path, kindly help me. I have checked in these forms, scripting guide…etc. but there is no helpful information.

 

I also checked below link:

http://forums.adobe.com/message/2794194#2794194

 

 

var myDocument = app.activeDocument;
var myDocName = myDocument.name;
 temp=myDocName.replace(/\.indd/g,"");
var myFileNme=temp.toString();
var myFolder =myDocument.filePath;
var to = new File(myFolder + "/" + myFileNme + "/");
var flag = Folder(to).create();
var copyingFonts = true;
var copyingLinkedGraphics = true;
var copyingProfiles = true;
var updatingGraphics = true;
var includingHiddenLayers = true;
var ignorePreflightErrors = true;
var creatingReport = false;
var versionComments = "comment";
var forceSave = true;
if ( flag === true){
    app.activeDocument.packageForPrint (
          to, 
          copyingFonts, 
          copyingLinkedGraphics, 
          copyingProfiles, 
          updatingGraphics, 
          includingHiddenLayers,
          ignorePreflightErrors, 
          creatingReport, 
          versionComments,
          forceSave
         );
}

 

 

Thanks in advance.

 

Regards,

Siva

 
Replies
  • Currently Being Moderated
    Mar 2, 2011 12:03 PM   in reply to siva k

    Pretty sure it isn't possible from JavaScript, you will likely need to involve AppleScript (or VBScript if on a PC).

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 4, 2011 12:26 AM   in reply to Mayhem SWE

    Hi,

     

    As Mayhem suggests, your solution is to call Applescript (Mac) or VB(PC). I don't know how that works in VB but in APS you can do this :

     

    do shell script "zip ..." 
    

     

     

    where ... are instructions that you can find with : zip -help in the terminal

     

    I don't have any clue how you do it through VB but google can help maybe.

     

    I was told there was a js library for zipping file but never used it.

     

    Hope it helps

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 7, 2011 9:55 PM   in reply to Loic_aigon

    This is Zip code for vb. I did a bad job with copy and paste so there got to be some errors. But the main idea is here.

     

     

    ' Pass path & name to original & zip file
    Sub CreateZip(OriginalFile,ZipFile)  
      
      Set oZipShell = CreateObject("WScript.Shell")  
      Set oZipFSO = CreateObject("Scripting.FileSystemObject")
      
      If Not oZipFSO.FileExists(ZipFile) Then
        NewZip(ZipFile)
      Else
         Set aFile = oZipFSO.GetFile(ZipFile)
         aFile.Delete
         NewZip(ZipFile)
      End If
     
      Set oZipApp = CreateObject("Shell.Application")
      
      sZipFileCount = oZipApp.NameSpace(ZipFile).items.Count
     
      aFileName = Split(OriginalFile, "\")
      sFileName = (aFileName(Ubound(aFileName)))
      
      'listfiles
      sDupe = False
      For Each sFileNameInZip In oZipApp.NameSpace(sZipFile).items
        If LCase(sFileName) = LCase(sFileNameInZip) Then
          sDupe = True
          Exit For
        End If
      Next
      
      If Not sDupe Then
        oZipApp.NameSpace(sZipFile).Copyhere sFile
     
        'Keep script waiting until Compressing is done
        On Error Resume Next
        sLoop = 0
        Do Until sZipFileCount < oZipApp.NameSpace(sZipFile).Items.Count
          Wscript.Sleep(100)
          sLoop = sLoop + 1
        Loop
        On Error GoTo 0
      End If
    End Sub
     
    Sub NewZip(sNewZip)
      
      Set oNewZipFSO = CreateObject("Scripting.FileSystemObject")
      Set oNewZipFile = oNewZipFSO.CreateTextFile(sNewZip)
        
      oNewZipFile.Write Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, 0)
      
      oNewZipFile.Close
      Set oNewZipFSO = Nothing
     
      Wscript.Sleep(500)
    End Sub
     
    

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 8, 2011 12:00 AM   in reply to siva k

    Hi Siva,

     

    It is quite possible to write from scratch your own ZIP generator in JavaScript, but fortunately you'll find various available libraries on the Internet to facilitate the job! Personaly I've used JSZip as a starting point:

     

    http://jszip.stuartk.co.uk/

     

    (There are only a few adjustments to make it work under ExtendScript.)

     

    @+

    Marc

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Mar 8, 2011 2:07 AM   in reply to Marc Autret

    But why would you want to? It's a big maintenance hassle and the operating system does a perfectly good job of providing a zip tool already.

    Siva, are you on a Mac or PC?

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 8, 2011 2:27 AM   in reply to John Hawkinson

    ditto john…

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Mar 9, 2011 1:45 PM   in reply to siva k

    OK, so where do you stand?

     

    Steven has provided VB code for creating zip files under Windows. Does it meet your needs? Do you need help integrating it with JavaScript? Or does it not work?

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Mar 10, 2011 7:30 PM   in reply to siva k

    Sorry for the delay. I had hoped someone with more VB experience would appear.

    It looks from Steven's example and from Googling that under Windows, the way you create .ZIP files is you manually create an empty ZIP file by writing the ZIP header, and then Windows will let you open the ZIP file and copy in files.

     

    You can call the VBScript code from JavaScript. I don't use InDesign under Windows, so I can't test this for you, but you put it all together something like this:

     

    var myDocument = app.activeDocument;
    var myDocName = myDocument.name;
    var temp=myDocName.replace(/\.indd/g,"");
    var myFileNme=temp.toString();
    var myFolder =myDocument.filePath;
    var to = new File(myFolder + "/" + myFileNme + "/");
    var tozip = myFolder+"\"+temp+".zip";
    var flag = Folder(to).create();
    var copyingFonts = true;
    var copyingLinkedGraphics = true;
    var copyingProfiles = true;
    var updatingGraphics = true;
    var includingHiddenLayers = true;
    var ignorePreflightErrors = true;
    var creatingReport = false;
    var versionComments = "comment";
    var forceSave = true;
    if ( flag === true){
        app.activeDocument.packageForPrint (
              to,
              copyingFonts,
              copyingLinkedGraphics,
              copyingProfiles,
              updatingGraphics,
              includingHiddenLayers,
              ignorePreflightErrors,
              creatingReport,
              versionComments,
              forceSave
             );
    }

    var makezip = [
    ' REM  Pass path & name to original & zip file',
    ' Sub CreateZip(OriginalFile,ZipFile)  ',
    '   ',
    '   Set oZipShell = CreateObject("WScript.Shell")  ',
    '   Set oZipFSO = CreateObject("Scripting.FileSystemObject")',
    '   ',
    '   If Not oZipFSO.FileExists(ZipFile) Then',
    '     NewZip(ZipFile)',
    '   Else',
    '      Set aFile = oZipFSO.GetFile(ZipFile)',
    '      aFile.Delete',
    '      NewZip(ZipFile)',
    '   End If',
    '  ',
    '   Set oZipApp = CreateObject("Shell.Application")',
    '   ',
    '   sZipFileCount = oZipApp.NameSpace(ZipFile).items.Count',
    '  ',
    '   aFileName = Split(OriginalFile, "\")',
    '   sFileName = (aFileName(Ubound(aFileName)))',
    '   ',
    '   REM listfiles',
    '   sDupe = False',
    '   For Each sFileNameInZip In oZipApp.NameSpace(sZipFile).items',
    '     If LCase(sFileName) = LCase(sFileNameInZip) Then',
    '       sDupe = True',
    '       Exit For',
    '     End If',
    '   Next',
    '   ',
    '   If Not sDupe Then',
    '     oZipApp.NameSpace(sZipFile).Copyhere sFile',
    '  ',
    '     REM Keep script waiting until Compressing is done',
    '     On Error Resume Next',
    '     sLoop = 0',
    '     Do Until sZipFileCount < oZipApp.NameSpace(sZipFile).Items.Count',
    '       Wscript.Sleep(100)',
    '       sLoop = sLoop + 1',
    '     Loop',
    '     On Error GoTo 0',
    '   End If',
    ' End Sub',
    '  ',
    ' Sub NewZip(sNewZip)',
    '   ',
    '   Set oNewZipFSO = CreateObject("Scripting.FileSystemObject")',
    '   Set oNewZipFile = oNewZipFSO.CreateTextFile(sNewZip)',
    '     ',
    '   oNewZipFile.Write Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, 0)',
    '   ',
    '   oNewZipFile.Close',
    '   Set oNewZipFSO = Nothing',
    '  ',
    '   Wscript.Sleep(500)',
    ' End Sub',
    'CreateZip("'+to+'","'+tozip+'")'
    ].join("\r\n");

    app.doScript(makezip, ScriptLanguage.visualBasic);

     

    Note that to avoid quoting frustrations, I just changed the single quote-based VB comment characters to REM statements. Supposedly that works.

    I also define tozip as the destination zip file, and then call the CreateZip subroutine as the last part of the VBscript.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 22, 2012 2:49 AM   in reply to John Hawkinson

    John Hawkinson wrote:

     

    ...You can call the VBScript code from JavaScript. I don't use InDesign under Windows, so I can't test this for you, but you put it all together something like this:

     

    I would found this JS_VBA_zip code very useful, but, unfortunatelly, it doesn't work.

    Looking for the reason:

     

    '   aFileName = Split(OriginalFile, "\")',

     

    backslash disappears, so I would change to "\\"

     

    '   For Each sFileNameInZip In oZipApp.NameSpace(sZipFile).items',

     

    variable sZipFile looks like undeclared, I am also not sure about sFile

     

    I am a beginner in scripting so, generally, got a problem with determine where is a mistake and where is my less of knowledge.

     

    Could you, John, or some of you, Masters, look back into this code, pls

    Thanks

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Feb 22, 2012 4:36 AM   in reply to Jump_Over

    I am a beginner in scripting so, generally, got a problem with determine where is a mistake and where is my less of knowledge.

     

    Could you, John, or some of you, Masters, look back into this code, pls

    Unfortunately, Jump_Over, I don't have the answer here. I merely took Steven's code from post #3 and wrapped it in JavaScript.

    You are correct that it looks like it has some real problems. I also think you are right about the backslash, but I am not sure what is intended with the undefined variables.

     

    I would suggest you look elsewhere for VB to create zip files. I know there have been other threads on this forum and almost certainly there are better places to look off of this forum. Sorry I can't be more helpful.

     
    |
    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