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?
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
Thanks to everyone, specially Marc for the code sample...
This ZIP-thing is not for the compressing the size, it´s more for easing up the next face of the workflow. It´s much more nicer to handle only one file instead of hundreds of them....=)
Script is actually made by Marijan "Tomaxxi" Tompa so I probably ask him if he had time to give this a try at some point..... this is not a busy case....
@John, I thought using OS too, but I try to keep this whole solution as OS independent as possible, so if there is any deasent generic solution I rather test it first. If it´s too slow or there are some other flaws, I´ll consider using OS based compression methods.....
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
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().
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
var test = app.doScript('do shell script "zip ~/Desktop/Zip/test3.zip ~/Desktop/Zip/test7/" ', ScriptLanguage.applescriptLanguage);
this command gives me this result as:
#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:
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 ...
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.
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.
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!)
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.
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.
North America
Europe, Middle East and Africa
Asia Pacific