create zip file via JSX
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
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");
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);
}
}
}
}
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.