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
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
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
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:
(There are only a few adjustments to make it work under ExtendScript.)
@+
Marc
Dear all,
I am extremely sorry for late replay. Thanks for all your kind and support. I need to upload my final artwork files on internet. With (Package) .zip + .pdf all tasks.
To do this I have script for Package+ pdf creation now I am requesting for instead of package folder, .zip can give the final result for my needs. So I can upload the directly .zip + .pdf this can help for my all daily tasks.
I am using Windows 7 operating system with InDesign CS4.
Thanks in Advance
Regards,
Siva
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.
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
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.
North America
Europe, Middle East and Africa
Asia Pacific