How do I re-zip/compress an expanded IDML file - adobe-indesign

I have an IDML file that I unzipped. I now want to compress the expanded folder back into an IDML file. I have access to a Mac or Linux machine.
What are the ways I can do this?
Zipping the file using zip (command line) or with Keka, BetterZip or Archive Utility don't work. InDesign issues the error:
Cannot open the file. Adobe InDesign may not support the file format, a plug-in that supports the file format may be missing, or the file may be open in another application.

The problem with regular zip is that the zip archive contains a “mimetype” file that shouldn’t be compressed if you want InDesign to identify the newly-created IDML. So the way you have to re-zip the file (and the way the ePub scripts work) is like this:
They first create a zip archive which contains only the mimetype file, uncompressed. zip -X0 'myfile.idml' mimetype
Then they add the rest of the files/folders into the zip archive, this time with full compression. zip -rDX9 "myfile.idml" * -x "*.DS_Store" -x mimetype
In shell script terms, the ePub scripts do this (assuming the current directory is the one containing all the IDML contents):
zip -X0 'myfile.idml' mimetype # create the zip archive 'myfile.idml', containing only the 'mimetype' file with no compression
zip -rDX9 "myfile.idml" * -x "*.DS_Store" -x mimetype # add everything else to the ‘myfile.idml’ archive, EXCEPT .DS_Store files and the ‘mimetype’ file (which is already there from the previous step)
To save you time reading the zip man page, here’s what all these options mean:
-X = “no extra” — do not save extra file attributes like user/group ID for each file
-0 = “compression level zero” — no compression
-r = “recurse paths” — go through everything in the directory, including nested subfolders
-D = “no directory entries” — don’t put special stuff in the zip archive for directories
-9 = “compression level 9 (optimal)”
-x = “exclude these files”
Follow this voodoo, and you should be able to create legal IDML files.
Source: http://indesignsecrets.com/topic/how-do-i-re-zipcompress-an-expanded-idml-file
A big thanks to Chuck Weger and David Blatner at http://indesignsecrets.com

From within InDesign
use this jsx script to expand an IDML
//DESCRIPTION: Expands an IDML file into folder format
ExpandIDML();
function ExpandIDML(){
var fromIDMLFile = File.openDialog("Please Select The IDML File to unpackage");
if(!fromIDMLFile){return}
var fullName = fromIDMLFile.fullName;
fullName = fullName.replace(/\.idml/,"");
var toFolder = new Folder(fullName);
app.unpackageUCF(fromIDMLFile,toFolder);
}
And that one to produce an IDML package:
//DESCRIPTION:Produces an IDML package from the contents of a directory:
CreateIDML();
function CreateIDML(){
var fromFolder = Folder.selectDialog("Please Select The Folder to package as IDML");
if(!fromFolder){return}
var fullName = fromFolder.fullName;
// var name = fromFolder.name;
// var path = fromFolder.path;
var toIDMLFile = new File(fullName+".idml");
app.packageUCF(fromFolder,toIDMLFile);
}

Related

Give name to a file within a zip archive which generated from stdout

I am running a postgresql query in a python script
copy (SELECT * FROM table) TO PROGRAM 'gzip > ./" + file_from + "' with csv HEADER;
The generated zip file has the expected name, but the file inside the zip archive does not have extension, it has the same as the zipfile minus the ".zip" extension. I would like to add the ".csv" extension to the filename without doing complex operations (e.g. unzip, rename, zip).
Thank you in advance.
Gzip does not create an archive like pkzip does.
If you send gzip's output to datadump.csv.gz then running gunzip against it will decompress it to a file named datadump.csv, but that is just a convenience feature that follows a convention and has no impact on what is actually inside the file.
Assuming that you want to use "gzip", the convention will be to create use ".csv.gz" as a suffix. Using "gunzip" on the file will result in filename.csv.
If the above example, set file_name to "whatever.csv.gz"
Using ZIP format is a little more complex, as zip works better with files. The equivalent command will be zip whatever.zip - to compress, and 'funzip whatever.zip > whatever.csv' to uncomrpess

Windows Script Host Javascript Get Path of .js file

I have been using QTTabBar for a while and am using .js scripts with it. The scripts are run using Windows Script Host, but I find myself having to specify hardcoded directories in the .js file instead of relative paths. This is not ideal.
In the .js file, is it possible to get the containing folder of the .js file (no matter what directory it is originally run from)? I just need to avoid specifying absolute paths somehow. For example, part of my .js file might look like this:
var qs = new ActiveXObject( "QTTabBarLib.Scripting" );
var fso = new ActiveXObject("Scripting.FileSystemObject");
var txtFile = fso.OpenTextFile("C:\\Installation\\Scripts\\QTTabBar\\dirs.txt", 1, false, 0);
var fText = txtFile.ReadAll();
I can't just put "dirs.txt" in the OpenTextFile function because when the .js script is run in QTTabBar, the working directory (I think) starts in system32 rather than at the .js file location. So I somehow need to get the path of the .js file itself and combine it with the relative name to create the absolute path. But I'm not sure if this is possible or how to do it.
You can get the path of current JScript file with
js_file_path = WScript.ScriptFullName;
and the absolute path to the text file is
path = WScript.ScriptFullName.split("\\").slice(0, -1).join("\\") + "\\dirs.txt";
No includes or imports are needed if the script is run in Windows Script Host.

bash zip omit files

I'd like to zip a folder, but zip skips files.
Folder structure is:
main_folder > sub_folder > file2.sql
file11.txt
file12.sql
Main_folder contains sub_folder and two files, subfolder contains one file.
When i use
zip -r $path *
i receive .zip file which contains everything except file11.txt. I tried various options but have not solved the problem. Zip makes correct structure and takes every single file except files from main_folder.
could you try this;
zip -r your.zip * -x file11.txt
man zip;
-x files
--exclude files
Explicitly exclude the specified files..

How to pack a Firefox extension from scratch

I am new to Firefox extensions and i would like you to help me pack one extension that i build and send it to some friends to test it.
My Extension is about to "block" some URLs. Which means that if someone tries to join "facebook.com" my extension should redirect him to "www.google.com"
the code is below.
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
Cu.import('resource://gre/modules/Services.jsm');
var urls_block = [
//If URLs contain any of these elements they will be blocked or redirected,
// your choice based on code in observer line 17
'www.facebook.com',
'www.apple.com'
];
var redir_obj = {
'www.facebook.com': 'http://www.google.com/',
'www.apple.com': 'http://www.samsung.com'
}
var observers = {
'http-on-modify-request': {
observe: function (aSubject, aTopic, aData) {
console.info('http-on-modify-request: aSubject = '
+ aSubject + ' | aTopic = ' + aTopic + ' | aData = ' + aData);
var httpChannel = aSubject.QueryInterface(Ci.nsIHttpChannel);
var requestUrl = httpChannel.URI.spec.toLowerCase();
for (var i=0; i<urls_block.length; i++) {
if (requestUrl.indexOf(urls_block[i]) > -1) {
//httpChannel.cancel(Cr.NS_BINDING_ABORTED); //this aborts the load
//Can redirect with this next line, if don't want to redirect and
// just block, then comment this line and uncomment the line above:
httpChannel.redirectTo(Services.io.newURI(redir_obj[urls_block[i]],
null, null));
break;
}
}
},
reg: function () {
Services.obs.addObserver(observers['http-on-modify-request'],
'http-on-modify-request', false);
},
unreg: function () {
Services.obs.removeObserver(observers['http-on-modify-request'],
'http-on-modify-request');
}
}
};
function install() {}
function uninstall() {}
function startup() {
for (var o in observers) {
observers[o].reg();
}
}
function shutdown(aData, aReason) {
if (aReason == APP_SHUTDOWN) return;
for (var o in observers) {
observers[o].unreg();
}
}
Big thanks to #Noitidart for his enormous help.
So i want to pack this code for Firefox Extension.
Could someone show me how to do it or any example?
Thanks a lot for your time helping me here.
At a minimum, you will need to create an install.rdf file and a chrome.manifest file. Go through those links, you are going to need to make some choices (e.g. what to call your extension, an <em:id>, etc.).
In addition, it appears that you are making a bootstrap/restartless add-on and should call the file containing the code you included in the question: bootstrap.js
.xpi file format (Extension Packaging):
The .xpi files that are used as containers for Mozilla (Firefox, Thunderbird, etc.) extensions are merely zip compressed archives that have had the file extension changed to .xpi. The files start in the root directory of the zip compressed archive (i.e. there is first level directory to contain the files). The files must either be uncompressed, or compressed using the "Deflate" algorithm. Using other compression algorithms will result in your .xpi file not loading and a popup being shown that the add-on is corrupt.
The contents of the archive could be only a few files to any number of files. At a minimum, you have an install.rdf and a chrome.manifest file. There will almost always be at least one additional file (if not many additional files).
My very simple Bootstrap/Restartless extension, Print Button is Print (changes the print button to print instead of print preview), has the following structure:
Archive contains:
bootstrap.js
chrome/
chrome/content/
chrome/content/options.xul
chrome/skin/
chrome/skin/printer-typeC128.png
chrome/skin/printer-typeC32.png
chrome/skin/printer-typeC48.png
chrome/skin/printer-typeC64.png
chrome.manifest
install.rdf
license.txt
Total 12 entries (42360 bytes)
There are the required install.rdf and chrome.manifest files.
The file bootstrap.js is required for Bootstrap/Restartless extensions. It contains the code that is run when the extension is installed, removed, enabled, disabled, or upon Firefox startup or shutdown. This extension is simple enough such that all the JavaScript code is contained in bootstrap.js.
There is a file chrome/content/options.xul which is a XUL definition of the options dialog.
The license.txt just explains that the extension was released under the Mozilla Public License, v2.0.
The .png files are the icon for this extension at various resolutions.
The install.rdf file for Print Button is Print is (all instances of PrintButtonIsPrint should be changed to something for your extension which you define in your chrome.manifest file; All of them you could just delete from the instal.rdf file if you wanted to as you have no options dialog, or icons defined (yet).):
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>PrintButtonIsPrint#makyen.foo</em:id> <!-- MUST be unique to your extension. -->
<em:version>1.0.1</em:version>
<em:type>2</em:type>
<em:name>Print Button is Print</em:name> <!-- Should be unique to your extension. -->
<em:bootstrap>true</em:bootstrap> <!-- Indicate that the extension is restartless -->
<em:unpack>false</em:unpack>
<em:description>Makes the Print Button print the page instead of presenting a print preview. Adds the option of using shift-left-click and/or ctrl-left-click for Print Preview (both enabled by default).</em:description>
<em:creator>Makyen</em:creator>
<!-- No about.
<em:aboutURL>chrome://PrintButtonIsPrint/content/about.xul</em:aboutURL>
-->
<em:optionsURL>chrome://PrintButtonIsPrint/content/options.xul</em:optionsURL>
<em:iconURL>chrome://PrintButtonIsPrint/skin/printer-typeC48.png</em:iconURL>
<em:icon64URL>chrome://PrintButtonIsPrint/skin/printer-typeC64.png</em:icon64URL>
<!--Firefox-->
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>29.0</em:minVersion>
<em:maxVersion>37.*</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>
The chrome.manifest is (both instances of PrintButtonIsPrint should be changed to something for your extension):
content PrintButtonIsPrint chrome/content/
skin PrintButtonIsPrint classic/1.0 chrome/skin/
To create the .xpi file I use a batch file, which uses a combination of DOS and Unix/Linux (actually Cygwin) commands:
mkxpi.bat:
rm -f PrintButtonIsPrint#makyen.foo.xpi
zip -1 -r PrintButtonIsPrint#makyen.foo.xpi * -x#xpi.ignore
pause
This removes any old version of the .xpi file. It then creates a new .xpi file using, -1, minimal compression (speed of access is more important than saving space) and containing all files and subdirectories ** but ignoring all the files in the xpi.ignore text file -x#xpi.ignore. Ignoring files is used because I have other things in the directory (e.g. .git directory, .bak files auto-created from editor, etc.). Once the .xpi file is created the script executes pause so that I can verify which files were included, that there were no errors, etc. instead of just having the window disappear and assuming that everything is fine.
My xpi.ignore file is a bit long, as it accumulates cruft from various projects and is rarely cleaned out:
*.com
*.class
*.dll
*.exe
*.o
*.so
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
*.log
*.sql
*.sqlite
*.svg
*/.DS_Store
*/.DS_Store?
*/._*
._*
*/.Spotlight-V100
.Spotlight-V100
*/.Trashes
.Trashes
*/ehthumbs.db
*/Thumbs.db
*.ORIG
*.bak
*OLD*
OLD/*
*/OLD/*
*.OLD
*.OLD[0-9]
*/OLD/*
*/OLD[0-9]/*
*.unknown
*.unknown[0-9]
*.updated
*.updated[0-9]
*/Copy *
*/OLD
*/OLD*
*/OLD[0-9]
*/OLD[0-9][0-9]
*/test/*
*/not in xpi/*
*/tmp
*.tmp
*/foo
*.foo
*checkpoint
.git
*/.git
.gitignore
*/.gitignore
xpi.ignore
mkclean.bat
mkclean.bat.DONTRUN
mkxpi.bat
*.xpi
*/devtools-toolbox-window.ico
*/devtools-webconsole.ico
*/JSConsoleWindow.ico
*/main-window.ico
*/places.ico
*/viewSource.ico
Installing extensions:
As to installing extensions (i.e. the .xpi file), it can be a simple matter of dragging and dropping it onto a Firefox window running the profile in which you desire it installed. For development/testing, you can have the extension be in a directory on your local drive by using a Firefox extension proxy file (create a file named as the extension's <em:id> in the profile's extensions directory containing one line with the complete path to the directory containing the extension's files). Depending on what your goal is (one profile, all profiles, all users, which OS, etc.), there are other options as to how to install extensions.
This answer was mostly copied from my answer here.

What is the fastest way to unzip textfiles in Matlab during a function?

I would like to scan text of textfiles in Matlab with the textscan function. Before I can open the textfile with fid = fopen('C:\path'), I need to unzip the files first. The files have the extension: *.gz
There are thousands of files which I need to analyze and high performance is important.
I have two ideas:
(1) Use an external program an call it from the command line in Matlab
(2) Use a Matlab 'zip'toolbox. I have heard of gunzip, but don't know about its performance.
Does anyone knows a way to unzip these files as quick as possible from within Matlab?
Thanks!
You could always try the Matlab unzip() function:
unzip
Extract contents of zip file
Syntax
unzip(zipfilename)
unzip(zipfilename, outputdir)
unzip(url, ...)
filenames = unzip(...)
Description
unzip(zipfilename) extracts the archived contents of zipfilename into the current folder and sets the files' attributes, preserving the timestamps. It overwrites any existing files with the same names as those in the archive if the existing files' attributes and ownerships permit it. For example, files from rerunning unzip on the same zip filename do not overwrite any of those files that have a read-only attribute; instead, unzip issues a warning for such files.
Internally, this uses Java's zip library org.apache.tools.zip. If your zip archives each contain many text files it might be faster to drop down into Java and extract them entry by entry, without explicitly unzipped files. look at the source of unzip.m to get some ideas, and also the Java documentation.
I've found 7zip-commandline(Windows) / p7zip(Unix) to be somewhat speedier for this.
[edit]From some quick testing, it seems making a system call to gunzip is faster than using MATLAB's native gunzip. You could give that a try as well.
Just write a new function that imitates basic MATLAB gunzip functionality:
function [] = sunzip(fullfilename,output_dir)
if ~exist('output_dir','var'), output_dir = fileparts(fullfilename); end
app_path = '/usr/bin/7za';
switches = ' e'; %extract files ignoring directory structure
options = [' -o' output_dir];
system([app_path switches options '_' fullfilename]);
Then use it as you would use gunzip:
sunzip('/data/time_1000.out.gz',tmp_dir);
With MATLAB's toc timer, I get the following extraction times with 6 uncompressed 114MB ASCII files:
gunzip: 10.15s
sunzip: 7.84s
worked well, just needed a minor change to Max's syntax calling the executable.
system([app_path switches ' ' fullfilename options ]);

Resources