Skip navigation
Currently Being Moderated

ZIP-package from indesign (by script)

Jun 20, 2011 7:28 AM

we have a javascript that writes lot´s of files from indesign... developers of the next step asked if it´s possible that indesign would package all those files to a ZIP-pacakge... is it possible?

 
Replies
  • Currently Being Moderated
    Jun 20, 2011 12:26 PM   in reply to Petteri_Paananen

    The application object has the very intuitively named methods packageUCF and unpackageUCF, intended to handle IDML files which themselves are ZIP.

     

    Dirk

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 20, 2011 12:41 PM   in reply to Dirk Becker

    IIRC, there were issues using those methods to create zips (most specifically with image files).

     

    This might be useful:

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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 20, 2011 1:52 PM   in reply to Petteri_Paananen

    Does it matter JPEGs cannot be compressed very well? If all of this is just to get a single package of files, then I'm tempted to do the PNG trick once more and attempt to create a ZIP file that contains uncompressed files only ...

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 20, 2011 6:01 PM   in reply to Petteri_Paananen

    JsZip is not very fast when 'wrapped' in ExtendScript, but it works.

     

    I think you only have to patch File / Folder access…

    Just found this old piece of code in my drawers:

     

    #include 'jszip/jszip.js'
     
    JSZip.prototype.addExistingFile = function(/*File*/f, newName)
    {
    var contents = false;
     
    if( f.constructor == File && f.exists && (f.encoding = 'BINARY') && f.open('r') )
         {
         contents = f.read();
         f.close();
         return this.add(newName||f.name, contents, {binary: true, date:f.modified});
         }
    throw new Error("Unable to open the file "+f);
    }
     
    // SAMPLE CODE
    /*
    var folder = app.activeScript.parent;
    var zip = new JSZip();
    zip.add("Hello.txt", "Hello World\n");
    
    zip.folder("images").
         addExistingFile(File(folder+"/test.jpg"));
    
    var content = zip.generate(true); // asBytes
    
    var f = File(folder+'/test.zip');
    f.encoding = 'BINARY';
    if( f.open('w') )
         {
         f.write(content);
         f.close();
         }
    */
    

     

     

    Hope that helps.

     

    @+

    Marc

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Jun 20, 2011 8:15 PM   in reply to Petteri_Paananen

    What OS? I really think you are much better off calling out to the operating system's zip utility. This is tricky under windows and trivial under Mac OS.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 20, 2011 11:07 PM   in reply to Harbs.

    Harbs,

     

    could you please clarify - were the images distorted somehow or was it just suboptimal compression (file size) as Jongware indicates?

     

    Thanks,

    Dirk

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 20, 2011 11:48 PM   in reply to Dirk Becker

    Dirk,

     

    I just checked my archives and found what I was remembering.

     

    Teus de Jong (OBM) had tried to use it for packaging ePubs and it failed for that purpose. Fonts and images were missing data.

     

    Harbs

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 21, 2011 4:09 AM   in reply to Harbs.

    I agree with John, zip system mechanism do that very well. I am quite sure code has been already been given for both platforms here :). 

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 28, 2012 1:21 PM   in reply to Petteri_Paananen

    Good evening,
    I can not use the script (on Mac) it gives me a syntax error ... but at first I want to open a used function without ".docx" "app.unpackageUCF () and app.packageUCF ()".

    thank you

     

    Bonsoir,

    Je ne parvient pas à utilisé le script (sur Mac) il me donne une erreur de syntaxe...   mais dans un premièr temps je veux ouvrir un ".docx" sans utilisé les fonction "app.unpackageUCF() and app.packageUCF()".

     

     

    Merci

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Feb 28, 2012 1:25 PM   in reply to Philippe Ruelle

    Philippe, you know your avatar image is stretched, right? You might want to fix that.

     

    This script cannot and should not work on a Mac.

    But on a Mac it is much much easier. Just use

     

    app.doScript('do shell script "zip filename.zip file1 file2 file3"', ScriptLanguage.APPLECRIPT_LANGUAGE);

     

    I cannot understand what you are saying about packageUCF().

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 28, 2012 1:45 PM   in reply to Petteri_Paananen

    if I'm not saying error!

     

    This function is two "app.unpackageUCF () and app.packageUCF ()" are passed by indesign me and I do not want.
    for the command line with Toolkit, it returns me the error "app.doscript is not a function".
    To open the docs, I guess I use the command "UNZIP".

     

    thank you
    Philippe

     


    C'est deux fonction "app.unpackageUCF() et app.packageUCF()" me font passé par indesign et je ne veux pas.

    pour la ligne de commande avec Toolkit, il me retourne l'erreur "app.doscript n'est pas une fonction".

    Pour ouvrir le docs, je suppose que j'utilise la commande "UNZIP".

     

    Merci

     

    Philippe

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Feb 28, 2012 2:14 PM   in reply to Philippe Ruelle

    I am having great difficulty understanding you.

     

    app.doScript is not the same as app.doscript. The 'S' is capitalized.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 29, 2012 4:25 AM   in reply to Petteri_Paananen
    Hello and thank you

    Is it possible to have an example that fonctione?

    Philippe

     

     

    Bonjour et merci

     

    Est-il possible d'avoir un exemple qui fonctione?

     

    Philippe

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 29, 2012 1:53 PM   in reply to Petteri_Paananen

    var test = app.doScript('do shell script "zip ~/Desktop/Zip/test3.zip ~/Desktop/Zip/test7/" ', ScriptLanguage.applescriptLanguage);

    this command gives me this result as:

    Capture d’écran 2012-02-29 à 21.32.59.png

     

    #target indesign

    var test = app.doScript('do shell script "zip ~/Desktop/Zip/test3.zip RS125_96B.pdf V8_Engine_Overhaul_Manual.pdf" ', ScriptLanguage.applescriptLanguage);

     

    this command gives me a file.

     

    var test = app.doScript('do shell script "zip ~/Desktop/Zip/test3.zip test7/*.pdf" ', ScriptLanguage.applescriptLanguage);

    this command does:

    Capture d’écran 2012-02-29 à 22.33.09.png

     

     

    and to extract the archive it is even harder (unzip).

     

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 1, 2012 12:31 PM   in reply to Petteri_Paananen
    Good evening or good morning

    The command app.doScript () function does not free the code "# target indesign" or set of ESKT indesign??

    I want to do a standalone script!

    Thank you ...

    Bonsoir ou bonjour

     

    La commande app.doScript() ne fonction pas sans le code " #target indesign" ou réglé ESKT sur indesign???

     

    Je veux faire un script autonome !

     

    Merci ...

     

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Mar 2, 2012 4:13 PM   in reply to Philippe Ruelle

    I'm sorry, Philippe, I'm still having a lot of difficulty understanding you.

    Maybe you could try to find someone who is a native speaker of English?

     

    Thanks, and sorry about that.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 2, 2012 7:48 PM   in reply to John Hawkinson

    John Hawkinson wrote:

     

    app.doScript('do shell script "zip filename.zip file1 file2 file3"', ScriptLanguage.APPLECRIPT_LANGUAGE);

     

     

    FWIW, ditto is a better choice than zip for Mac stuff.

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Mar 2, 2012 8:01 PM   in reply to Shane Stanley

    FWIW, ditto is a better choice than zip for Mac stuff.

     

    Gosh, that's an interesting question, Shane!

     

    From a portability perspective, that's untrue, at least from my background.

    zip works across all Unix systems, and even works under Windows if you have Cygwin or whatnot.

     

    ditto is Mac-specific.

     

    But you're right, ditto has signicant features that zip does not. Specifically it supports resource forks and and HFS metadata.

     

    But ditto also has annoying command-line syntax do that. Is it truly neccesary to use "ditto -c -k --sequesterRsrc --keepParent srcdir srcdir.zip"?

     

    In fairness, I guess one has to use "zip -r srcdir.zip srcdir" but it still seems a lot cleaner.

     

    Ah well.

     

    I guess I would use zip just for simplicity, but I see why others might disagree.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 3, 2012 1:53 AM   in reply to John Hawkinson

    John, I also use ditto for zip and have done for some time… Never caused me any problems… Horses for courses…

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Mar 3, 2012 8:05 AM   in reply to Muppet Mark

    Wha-huh? Mark, nobody said ditto caused anyone problems. It's just a Mac-only tool with a complex command-line syntax that is extremely verbose.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 3, 2012 10:05 AM   in reply to Petteri_Paananen

    Hello

    Ditto with, is it possible to exclude *. DS_Store.

    thank you

     

    Bonjour

     

    Avec ditto, est-il possible exclure les *.DS_Store.

     

    Merci

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Mar 3, 2012 12:33 PM   in reply to Philippe Ruelle

    Phillipe asks:

    Ditto with, is it possible to exclude *. DS_Store.

    No. With ditto, it is not possible to exclude files or directories.

     

    You could copy the directory first with "cp" and remove the .DS_Store file.

    You could delete the .DS_Store file for the zip archive using zip -d.

    Or you could simply create the zip file using zip.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 4, 2012 1:29 AM   in reply to Petteri_Paananen

    Hello,

     

    The ultimate goal set to open a IDML, modify and close without open Indesign.

    Philippe

     

     

    Bonjour,

    Le but final set de pouvoir ouvrir un idml, le modifier et le refermer sans avoir Indesign ouvert.

    Philippe

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 4, 2012 5:25 AM   in reply to Philippe Ruelle

     

    Philippe Ruelle wrote:

     

    The ultimate goal set to open a IDML, modify and close without open Indesign.

     

    If this script still needs to run inside InDesign, that would be rather pointless

     

    Oh let's have Google Translate a go at this as well: "Si ce script doit encore courir à l'intérieur d'InDesign, ce serait plutôt inutile " (Don't you trust your own English? At times I have to revert to your original in French to have it make sense!)

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 4, 2012 7:00 AM   in reply to Petteri_Paananen
    I want to change or create database files (the sound of txt)
    But also a docx file conversion to IDML or Adobe InDesign tagged text ...

    I'll cross that I travailier faster in Perl.
    thank you

     

    Google translation.

     

     

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 4, 2012 4:22 PM   in reply to John Hawkinson

    John Hawkinson wrote:

     

    FWIW, ditto is a better choice than zip for Mac stuff.

     

    Gosh, that's an interesting question, Shane!

     

    From a portability perspective, that's untrue, at least from my background.

    zip works across all Unix systems, and even works under Windows if you have Cygwin or whatnot.

     

    ditto is Mac-specific.

     

    Which is why I said "for Mac stuff". Your script included ScriptLanguage.APPLECRIPT_LANGUAGE, so I assumed that was a given.

     

    The syntax is verbose, but it essentially lets you match what using the Finder's Compress command does. zip's syntax is simpler, but then you have to manually organize things like a wrapper folder, and so on.

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Mar 4, 2012 4:43 PM   in reply to Shane Stanley

    Which is why I said "for Mac stuff". Your script included ScriptLanguage.APPLECRIPT_LANGUAGE, so I assumed that was a given.

    Well, I'm living in a fantasy world where "portability" doesn't mean "Windows and Mac" it means "Linux, Solaris (umm), Unix, etc."

    You're free to argue this is completely unreasaonble since InDesign won't be running on any such platforms any time soon.

     

    The syntax is verbose, but it essentially lets you match what using the Finder's Compress command does. zip's syntax is simpler, but then you have to manually organize things like a wrapper folder, and so on.

    Sure. Though if Philippe is really just editing IDML, this is all academic.

     
    |
    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