Copy link to clipboard
Copied
hello everyone!
I am planning to create a zip file containing a list of images generated from a PSD using "JSX"
is there a way to zip all exported images via Javascript
Thanks
I haven't written the Mac function yet, ditto is the best approach but there are some issues with it, I may have to use OSAScript/AppleScript and the System Archive Utility instead. But this works for Windows at least. Apache-licensed if you feel like forking it.
/*
Utility Pack Scripts created by David M. Converse ©2018-21
This script calls system functions to create a zip archive
Windows-only at present
Last modifed 6/7/2021
Licensed under the Apache License, Version 2.0 (the "License");
...
Copy link to clipboard
Copied
Play with methods for decompression and then try to do what you need perhaps yourself: Unzip a file
Copy link to clipboard
Copied
Thanks for the reply,
This put me on the right track
Copy link to clipboard
Copied
You could end up with a HUGE zip file. It is possible, I have a Bridge script in development that zips a set of files via command line.
Are you on Windows or Mac?
Copy link to clipboard
Copied
Thanks for the reply
I will have to use both it depends on the user machine
I am trying to execute this on a windows machine
var cmd = 'powershell -Command "Compress-Archive -Path %cd%\application\slices* -DestinationPath %cd%\application\zip2.zip"';
app.system(cmd);
I don't know if it works or I can run a batch that does the job for me
any advice?
Copy link to clipboard
Copied
I haven't written the Mac function yet, ditto is the best approach but there are some issues with it, I may have to use OSAScript/AppleScript and the System Archive Utility instead. But this works for Windows at least. Apache-licensed if you feel like forking it.
/*
Utility Pack Scripts created by David M. Converse ©2018-21
This script calls system functions to create a zip archive
Windows-only at present
Last modifed 6/7/2021
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#target bridge
if(BridgeTalk.appName == 'bridge'){
if(Folder.fs == 'Windows'){ //Windows-only for now
//create menu
var archCommand = MenuElement.create('command', 'Create Zip Archive...', 'at the end of Tools');
var archCommandc = MenuElement.create('command', 'Create Zip Archive...', 'after Thumbnail/Open', this.menuID); //add to Contextual menu
archCommand.onSelect = function(){
zipArchive();
}
archCommandc.onSelect = function(){
zipArchive();
}
function zipArchive(){
try{
var sels = app.document.selections;
if(sels.length == 0){
return;
}
if(Folder.fs == 'Windows'){
var inputName = '\'' + sels[0].spec.fsName + '\'';
for(var i = 1; i < sels.length; i++){
inputName = inputName + ' , ' + '\'' + sels[i].spec.fsName + '\'';
}
inputName = inputName.replace(/\//g, '\\');
var archFile = new File('~/Desktop/archive.zip').saveDlg('Create New ZIP Archive', '*.zip'); //create text file
var archName = '\'' + archFile.fsName + '\'';
archName = archName.replace(/\//g, '\\');
app.synchronousMode = true;
var archivestr = 'CreateObject("Wscript.Shell").Run "powershell -NoLogo -NoProfile -Command Compress-Archive -LiteralPath '+ inputName +' -DestinationPath ' + archName + '", 0, True';
var vbstempFile = new File(Folder.temp + '/vbstemp.vbs');
vbstempFile.open ('w'); //save vbs file
vbstempFile.write(archivestr);
vbstempFile.close();
File(vbstempFile).execute(); //execute vbs file
$.sleep(1500);
File(vbstempFile).remove();
app.synchronousMode = false;
}
else{
alert('Mac implementation not yet available. Please stay tuned for updates.');
return;
}
}
catch(e){
alert(e + e.line);
}
}
}
}
Copy link to clipboard
Copied
Thanks for the reply,
what I actually did was I created a .bat file from jsx and and wrote the code inside of it that zips all the assets delete the folder andthe batch file itself.
I think this can solve my issue for the time being, this is the code hopefully it can be helpful to anyone
function zipFiles(){
var fullPath = activeDocument.path + "/application/compress.bat";
var file = new File(fullPath);
var batchcontent = 'powershell -Command "Compress-Archive -Path %cd%\\slices\\* -DestinationPath %cd%\\archive.zip" \n powershell Remove-Item "%cd%\\slices" \n Del compress.bat'
file.open('w');
file.write(
batchcontent
);
file.close();
}
zipFiles()
Copy link to clipboard
Copied
So now you need the same for macOS 😛
Copy link to clipboard
Copied
zip and ditto work similarly but not exactly on macOS, ditto will work on a folder but not scattered individual files. Dude's code above zips a folder while mine zips a set of selected files regardless of location.
Copy link to clipboard
Copied
will this also work on windows?
Copy link to clipboard
Copied
Confirm that's a joke, not a SpamBot activity otherwise you'll get banned 😉
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I asked to be sure as we have lately flood of bots over here 😉
Copy link to clipboard
Copied
I am not a bot. don't beleive me? throw me some 2+2 question.