Copy link to clipboard
Copied
Hi All,
Is there a way to unzip a password-protected file using InDesign JavaScript?
Please provide some examples if possible.
Thanks,
Shonky
Google this:
javascript unzip password
And you'll get the answer(s) you're looking for. You're not going to like them very much I don't think but that's your lot.
Copy link to clipboard
Copied
A lot of files are actually ZIP archives (EPUB, MS Office, etc.) and have to be accessed through an archive opener. I'm pretty sure there are standard code examples and library routines for both regular ZIP and PW-protected ZIP files out there; not sure if they mesh with ID's version of things.
I've been looking for a good module to do just that, for other purposes, preferably with seamless PW control built in. Haven't found one, but I'm feeble on JS, my programming era being a while back.
Copy link to clipboard
Copied
Thanks James for your reply!
Zip and Unzip using InDesign JavaScript is possible but I am looking if we can extract a PW protected zip file using InDesign JavaScript.
Thanks,
Shonky
Copy link to clipboard
Copied
If you're on Mac then you can use the unzip shell command. I don't know if shell scripts can be called directly from JavaScript, if not then you'll need to use doScript command in JavaScript to call do shell script AppleScript.
Copy link to clipboard
Copied
Thanks Leo! But I need it to work on Mac and Windows both. I found a Zip.js library, here is a link
https://gildas-lormeau.github.io/zip.js/
But I am unable to use it in InDesign, I hope someone expert here can help me.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
There are some examples for Windows:
https://stackoverflow.com/questions/10186813/how-to-run-cmd-exe-with-parameters-from-javascript
Something similar should be somewhere for Mac.
Copy link to clipboard
Copied
Thanks Robert!
Can you please provide example with unzip with password?
Copy link to clipboard
Copied
Everything depends on unzip tool you plan to use...
Copy link to clipboard
Copied
You would have to use an external language that can perform the unzip function then call an Extendscript routine on the unzipped packaged.
Copy link to clipboard
Copied
Thanks Brian, I tried to use zip.js but it's not working in InDesign JavaScript, and not sure for any other external library which support InDesign.
Copy link to clipboard
Copied
You can unzip a zip file using unpackageUCF():
app.unpackageUCF (
File ('myZip.zip'),
Folder ('d:/unzipped/')
);
Though probably password-protected zip files will be refused, but that will be the case with all unpackers. You'll have to look for a utility that allows a password as an input parameter, and you'll have to get the password from the party that produced the zip file.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
What is wrong with my example?
You just need to find unzipping tool, check params for it to unzip password protected files and then build string to use in my example?
Similar principle for Mac - you just need to Google it.
Copy link to clipboard
Copied
Maybe not a very straightforward answer - but an example how to execute shell command on Mac:
Copy link to clipboard
Copied
Google this:
javascript unzip password
And you'll get the answer(s) you're looking for. You're not going to like them very much I don't think but that's your lot.